Difference between Primary and Candidate Key

Prerequisite – DBMS | Keys in Relational Model
Both Primary Key and Candidate Key are the attributes that are used to access tuples from a table. These(Primary key and Candidate key) are also can be used to create a relationship between two tables.

Primary Key:
Primary Key is a set of attributes (or attribute) which uniquely identify the tuples in a relation or table. Primary key is a minimal super key, so there is one and only one primary key in any relation. For example,

Student{ID, F_name, M_name, L_name, Age} 

Here only ID can be primary key because name, age and address can be same but ID can’t be same.

Candidate Key:
Candidate key is a set of attributes (or attribute) which uniquely identify the tuples in a relation or table. As we know that Primary key is a minimal super key, so there is one and only one primary key in any relation but There is more than one candidate key can take place. Candidate key’s attributes can contain NULL value which oppose to the primary key. For example,

Student{ID, First_name, Last_name, Age} 

Here we can see the two candidate keys ID and {First_name, Last_name, DOB}. So here, there are present more than one candidate keys, which can uniquely identifies a tuple in a relation.

Difference between Primary and Candidate Key:

S.NO Primary Key Candidate Key
1. Primary key is a minimal super key. So there is one and only one primary key in a relation. While in a relation there can be more than one candidate key.
2. Any attribute of Primary key can not contain NULL value. While in Candidate key any attribute can contain NULL value.
3. Primary key can be optional to specify any relation. But without candidate key there can’t be specified any relation.
4. Primary key specifies the important attribute for the relation. Candidate specifies the key which can qualify for primary key.
5. Its confirmed that a primary key is a candidate key. But Its confirmed that a candidate key can be a primary key.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.