+ 1

What is the difference between UNIQUE and PRIMARY KEY?

27th Sep 2015, 7:54 AM
Lina
2 Réponses
+ 3
PRIMARY KEY(PK) can be set to only 1 column whereas UNIQUE can be set across multiple columns in a table. Also, UNIQUE constraint accepts NULL values whereas PK doesn't.
2nd Oct 2015, 11:16 AM
Daniel Pereira
Daniel Pereira - avatar
0
Primary Key Primary key cannot have a NULL value. Each table can have only one primary key. By default, Primary key is clustered index, and the data in database table is physically organized in the sequence of clustered index. Primary key can be related to another tables as a Foreign Key. We can generate ID automatically with the help of Auto Increment field. Primary key supports Auto Increment value. We can define Primary key constraint on temporary table and table variable. We can't delete primary key value from the parent table which is used as a foreign key in child table. To delete we first need to delete that primary key value from the child table. Unique Key Unique Constraint may have a NULL value. Each table can have more than one Unique Constraint. By default, Unique key is a unique non-clustered index. Unique Constraint can not be related with another table's as a Foreign Key. Unique Constraint doesn't supports Auto Increment value.
25th Nov 2016, 5:57 AM
Akwin Lopez
Akwin Lopez - avatar