Check Uniqueness in a table SQL

  • Hi Guys,

    I need a good way to check uniqueness of data in a specific table.

    For instance, if i have a table 1,2,3,4,5

    How do I make sure that 1 appears only once in this table?

    Thanks,

  • anyone??

  • I have no idea what you mean.

    Do you have 5 tables named "1", "2", "3", "4" and "5"?

    Do you have 1 table with 5 columns named "1", "2", "3", "4" and "5"?

    Do you have 1 table with 1 column and 1 record with value "12345"?

    Do you have 1 table with 1 column and 5 record with values "1", "2", "3", "4" and "5"?


    N 56°04'39.16"
    E 12°55'05.25"

  • Try to add a UNIQUE index or an UNIQUE constraint.


    N 56°04'39.16"
    E 12°55'05.25"

  • You could create a UNIQUE index on the column and be sure it does not allow nulls. If there are duplicates you would get a message and the create index would fail.

    Spotting duplicates can be also done via query.

    select col1 from table

    group by col1

    having count(col1) > 1

    Toni

  • Thanks a lot you guys =)

  • Hi,

    You can use UNIQUE constraints to make sure that no duplicate values are entered in specific columns that do not participate in a primary key. Although both a UNIQUE constraint and a PRIMARY KEY constraint enforce uniqueness, use a UNIQUE constraint instead of a PRIMARY KEY constraint when you want to enforce the uniqueness of a column, or combination of columns, that is not the primary key.

    Multiple UNIQUE constraints can be defined on a table, whereas only one PRIMARY KEY constraint can be defined on a table.

    Also, unlike PRIMARY KEY constraints, UNIQUE constraints allow for the value NULL. However, as with any value participating in a UNIQUE constraint, only one null value is allowed per column.

    Thanks -- Vj

    http://dotnetvj.blogspot.com

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply