Wednesday 10 May 2017

Difference between Primary Key and Unique Key?

In this post, I will explain the difference between Primary Key and Unique Key.


Primary Key and Unique Key provide uniqueness for a column or set of columns in a table. But there are different characteristics or behaviour of them, which makes Primary Key and Unique Key different. Please find below the difference between Primary Key and Unique Key :


Sr No
Primary Key
Unique Key
1
A database table can have only one Primary Key.
A database table can have more than one Unique Key.
2
Primary Key is not nullable (Doesn't allow NULL value).
Unique Key is nullable (Allows at least one NULL value).
3
Primary Key generates a Unique Clustered Index.
Unique Key generates a Unique Non-Clustered Index.
4
Primary Key is used to identify a row (a record) in a table.
Unique Key is used to prevent duplicate values in a column.


0 comments:

Post a Comment

Please do not enter any spam link in the message box.