Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2003
    Posts
    104

    Unanswered: Forcing a table to only accept unique new data?

    Hi All,
    this should be a simple SQL problem. I have a table called Users with columns [ID] (auto ID), [UserName] and [Description] (see example below)

    ID UserName Description

    12 Eveddar Eddie Veddar

    I wish to ADD (insert) a row into this table, but I want to make sure no two identicaln rows exist. That is, i do NOT want something like this to be in the table:


    ID UserName Description

    12 Eveddar Eddie Veddar
    13 Eveddar Eddie Veddar


    How can i write an INSERT statement that will prevent duplicates of this kind?

    Thanx in advance

    or how cna you modify this insert statement?

    INSERT
    INTO Users(UserName,Description)
    VALUES ('Eveddar','Eddie Veddar');

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    CREATE UNIQUE INDEX NoDupeUsers
    ON Users
    (
    UserName ASC,
    Description ASC
    )

    see http://support.microsoft.com/default...NoWebContent=1

  3. #3
    Join Date
    Nov 2003
    Posts
    104
    The tables have already been created!!!

    Also, Where do I run this SQl code you gave me. All i need is a modification of the SQL INSERT statement that will make sure any inserted row is "unique"

    (Sorry I am just a bit confused)

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    yes, i know the table already exists, this will create a unique index on the table

    go to Query > New > View > SQL View

    paste the query and run it

    now you will not be able to enter duplicates


    rudy

  5. #5
    Join Date
    Nov 2003
    Posts
    104

    thanx

    Oh sweet. Thanx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •