An Idea can change your life.....

Thursday, October 29, 2009

What's the difference between a primary key and a unique(Candidate) key

uniqueness
Both primary key and unique key enforces uniqueness of the column on which they are defined.
Indexes

  • primary key creates a clustered index on the column
  • unique creates a nonclustered index by default
Nulls
  •  primary key doesn't allow NULLs
  •  but unique key allows one NULL only.
Multiple
  • you can have multiple unique keys in a table
  • can have only one Primary Key
Both of them can be refered as Foreign Key

A foreign key is a column (the child collumn) in a table which has a corresponding relationship and a dependency on another collumn (the parent collumn) that is usually in a different table.

No comments: