/    Sign up×
Community /Pin to ProfileBookmark

Database – avoiding duplicate entries

I’m working on a web application, and the application allows people to enter, edit, and search for people. I have one table that stores all people, and an autonumber is automatically assigned to a person when they are entered. Therefore, since I’m using an autonumber as a primary key, there is the possibility that a person can be duplicated.

I want to avoid duplicates as much as possible. I’ve thought of 2 solutions, but I’d really like to hear more. Here’s what I have:

[list=1]

  • [*]

    Don’t provide the user with a link to the entry page until they’ve ran a search (i.e., the link to the entry page is on the search page).


  • [*]

    After submission on the entry page and before the record is written, show a list of possible candidates for the information that was entered. If the person already exists, they can cancel the entry process.


  • [/list]

    What are some other techniques I can use to avoid duplicate names?

    to post a comment
    Full-stack Developer

    2 Comments(s)

    Copy linkTweet thisAlerts:
    @welshFeb 04.2006 — wut serverside are u using? but with php you can do something like this:
    [code=php]
    $connection = mysql_connect($host,$user,$password) or die ("Couldn't connect to server.");
    $db = mysql_select_db($database, $connection) or die ("Couldn't select database.");
    $sql = "SELECT name FROM table WHERE name='$fname'";
    $result = mysql_query($sql) or die("Couldn't execute query.");
    $num = mysql_numrows($result);
    if ($num > 0)
    {
    $message_new = "$fname already used. Select another.";
    echo $message_new;
    }
    else
    {

    /* if the name doesnt exist then post what you want to happen here */
    }
    [/code]

    fname was the name posted by user so make sure u have that i didnt cause im tired. but basically it querys the database to see if there are any rows containing the name in it the sets $num to that numbers of rows, obviously the max is one so if the variable $num is 1 then it posts the message, if it isnt then the other stuff process's. this should be vary easy to adapt to another servside if u arent useing php, this is what i generally use because its simple and works.
    Copy linkTweet thisAlerts:
    @ray326Feb 04.2006 — First you have to define what constitutes "a duplicate name". An auto-increment field is not enough of a primary key if it doesn't prevent the entry of what you define as a "duplicate." In fact it's a total waste. Define a multi-field (concatenated) primary key on the table that will prevent the problem, i.e. that will encompass what you would call a unique name.
    ×

    Success!

    Help @chadjohnson spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.29,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...