The most successful people in any walks of lives may not be the most talented ones but are definately the most passionate & dedicated ones.

Monday, September 13, 2010

Differenc between Primary Key and Unique key

The differences between Primary Key and Unique key are as follows.

1) Primary Key is a combination of Unique and not--null constraints, so it can’t have duplicate values or any NULL whereas Unique key can contain null value.

2) A table can have only one PK whereas it can have any number of UNIQUE Key[s].

3) (a) For Oracle UNIQUE Key can have any number of null (because in oracle one null value can't be compared another null value)
(b) For Sybase, I have tested myself that it would not allow null at all in Unique keys
(c) For SQL Server it can have only one NULL (I couldn't get a chance to test this myself)

4) By default Primary Key will generate Clustered Index whereas Unique Key will Generate Non-Clustered Index.


Wish you a happy learning.

Thanks !!!

No comments:

Post a Comment