Thursday, October 16, 2008

Primary key and Unique key difference

Primary key and unique are Entity integrity constraints.

Primary key allows each row in a table to be uniquely identified and ensures that no duplicate rows exist and no null values are entered.

Unique key constraint is used to prevent the duplication of key values within the rows of a table and allow null values.

1. Unique key can be null, but Primariy key can't be null.
2. Primariy key can be refrenced to other table as FK.
3. We can have multiple Unique key in a table, but Primariy key is one and only one.
4. Primariy key itself is a unique key.

No comments: