Monday, September 3, 2012

Difference between Primary Key and Candidate Key



Difference between Primary Key and Candidate Key:
Primary key is a uniquely identifies each record in the relation, it cannot accept null values. The primary key may be one attribute or a composite of attributes, e.g.
you may have your (customerID) as primary key or (CustomerID and RespID) as a primary key.
Candidate key is a unique and not null key (similar to primary key) this candidate key is qualified to be a primary key, for some reason you didn’t choose it as a key.
Primary key = Unique + Not Null.
Candidate key = Unique + Not Null.
Example:
Consider a company has a Customer table that contains all customer information CustomerID, and customerName, Phone, SSN, …, etc.
If CustomerID is unique and not null the company may take it as a primary key. And SSN is unique but if it did not accept null values it will be the candidate key (Notice you can choose SSN as a primary key and CutomerID as candidate key and vice versa).
Simply candidate key is like a primary key but you didn’t choose it as a primary key.

Written by:
Elmozamil Elamir Hamid

No comments:

Post a Comment

Card