Saturday, December 4, 2010

Difference Between Primary Key and Unique Key

Everybody knows about difference between Primary key and Unique key who is/was working with SQL. This is silly question but still in lots of interview, interviewer asking this question starting from Fresher post to Experience post. This is a basic question and you must be aware with all the differences. You may know the difference but may be not all.



Primary Key..
1.It will not accept null values.
2.There will be only one primary key in a table.
3.Clustered index is created in Primary key.
4.Primary key allows each row in a table to be uniquely identified and ensures that no duplicate rows exist.
Unique Key..
1.Null values are accepted.
2.More than one unique key will be there in a table.
3.Non-Clustered index is created in unique key.
4.Unique key constraint is used to prevent the duplication of key values within the rows of a table and allow null values.
If you know any differences other than this than please share with me and others by commenting below or send me an email. I will update the post.

No comments:

Post a Comment