Friday, August 12, 2011

Difference between Primary Key and Unique Key in SQL Server


Difference between Primary key and Unique Key
(Primary key vs Unique key)

  • Both primary key and unique enforce uniqueness of the column on which they are defined.

  • But, by default, primary key creates a clustered index on the column, where as unique key creates a non- clustered index by default.

  • Another major difference is that, primary key doesn't allow NULLs, but unique key allows one NULL only.

  • Also, there can only be one primary key, while there can be many Unique keys


No comments:

Post a Comment