Saturday, May 17, 2008

Difference between "PRIMARY KEY" or "UNIQUE KEY"

Primary Key

1. we can create only one primary key per table.
2. primary key create cluster index
3. primary key provide two constriant inforceness "unique + not null"
4. we can reference primary key for foreign key constraint.

Unique Key

1. we can create more than one unique key per table
2. unique key create non-cluster index
3. unique key provide only "uniqueness for table" ( means we can't insert Duplicate value in same column.)
4. we can reference unique key for foreign key constraint.

Not Null
1. we can create more than one not null constraint per table
2. not null provide NON-NULL value in table ( we can insert NULL value in table)
3. we can't reference NOT NULL key for foregin key constraint.

According Foriegn key constraint reference.
We can use both "Primary key OR (NOT NULL + UNIQUE KEY).
But all three constraint have difference purpose and Definition.


No comments:

Subscribe via email

Enter your email address:

Delivered by FeedBurner