Pages

Monday, April 6, 2009

Difference between Primary and Unique Key Constraint

Do you know what is the difference between Primary Key and Unique Key Constraint?

If YES then You can display your name on my Blog.

Hurry-up post your reply by adding your comments on or before 08-APR-2009 (Last Day)

If you need any reference or help on this please check out my March and April Articles in Archive Section.

NOTE: Please do not copy the content from any other site.

I have got over 20 responses in my mail-box due to issues in posting the answers in the comment section and out of that selected "Aashish" as the winner of contest.

According to Aashish the Differences are:
1.Primary Key by definition cannot be null, where as unique key can accept null values but if the unique key is defined on a column which is not null , then this unique key can also be used as an alternate primary key functionality to identify unique rows in a table.
2.By definition you can have only one primary key defined on a table where as you can have multiple unique keys defined on a table
3.Also by default Primary key is created as clustured index and unique key is created as non clustered index.

This is the perfect answer to this question.

4 comments:

Anonymous said...

Your blog is very good.
The only difference which i can think of is Primary Key does not allow null values where Unique Key does.
Thanks and Regards
Sandhya_vemulla@yahoo.com

Ashish Kumar said...

Hi vijay
According to my knowledge
1.Primary Key by definition cannot be null, where as unique key can accept null values but if the unique key is defined on a column which is not null , then this unique key can also be used as an alternate primary key functionality to identify unique rows in a table.
2.By definition you can have only one primary key defined on a table where as you can have multiple unique keys defined on a table
3.Also by default Primary key is created as clustured index and unique key is created as non clustered index.

Vijaya Kadiyala said...

Hi Aashish
Very Well Said...You have the perfect 3 points.

RaviEG said...

Hi,

Its very useful blog, in addition to that,
Unique key will allow only one null value.

Regards,
Ravi.EG