11
Reply

Define Unique Key?

Ankur Jain

Ankur Jain

10y
1.2k
0
Reply

    The UNIQUE constraint uniquely identifies each record in a database table. The UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness for a column or set of columns. A PRIMARY KEY constraint automatically has a UNIQUE constraint defined on it. Note that you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table.

    UNIQUE key also work same as primary key and allows only unique value in table, but the other feature is that it allows ONLY ONE NULL VALUE also (because NULL also a value for database) whereas primary key does not allows any NULL value in table.

    Unique key is a one or more column that must be unique for each row of the table. It is similar to primary key. Primary key column will not accept a null. Whereas the unique key column will accept a null values.

    Unique keys can be more than one

    UNIQUE key also work same as primary key and allows only unique value in table, but the other feature is that it allows ONLY ONE NULL VALUE also (because NULL also a value for database) whereas primary key does not allows any NULL value in table.

    unique key eliminates the duplication of values and does allow the values uniquely. but unique key allows the NULL values. if u take primary key it won't allow duplications and it won't allow NULL values also.. one more important thing is, if you want to import the foreign key on any column that column must imposed with primary key. here you can't use the unique key...

    it allows unique values only

    To ensure no duplicate values are entered in specific columns that do not participate in a primary key. Creating a unique constraint automatically creates a corresponding unique index.

    Primary key is only one in a table but unique key can be more then one. primary key does not have null value but unique can have one null value. primary key is by default clustered index but unique is by default non-clustered index. primary key has reference key in another table and unique key also has reference key in another table.

    http://dotnet-munesh.blogspot.in/2013/12/difference.html

    Unique key is a constraint which enforces uniqueness of values.