Skip to content
Related Articles

Related Articles

Difference between Primary and Candidate Key
  • Difficulty Level : Easy
  • Last Updated : 22 Mar, 2021

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 relation or table. The primary key is a minimal super key, so there is one and only one primary key in any relationship. For example, 
 

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

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

Candidate Key: 
A candidate key is a set of attributes (or attribute) which uniquely identify the tuples in 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 relationship but there is more than one candidate key can take place. Candidate key’s attributes can contain a NULL value which opposes 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 identify a tuple in a relation. 

Difference between Primary and Candidate Key: 
 

S.NOPrimary KeyCandidate 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 not confirmed that a candidate key can be a primary key.
My Personal Notes arrow_drop_up
Recommended Articles
Page :