Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

difference between a primary key and a unique key?

Ads

 
 

Share on Google+Share on Google+

hemant kumar
difference between a primary key and a unique key?
1 Answer(s)      6 years and 8 months ago
Posted in : SQL

What's the difference between a primary key and a unique key?

Ads
View Answers

November 15, 2010 at 12:52 PM


Hi,

The column holding the primary key constraint cannot accept null values.whereas column holding the unique constraint can accept null values.

Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index(physical sorting of a database table?s) on the column, where are unique creates a non clustered index (sorted list of references to the table itself.) by default. Another major difference is that, primary key doesn't allow Nulls, but unique key allows one NULL only.

Thanks,


Ads