Open In App

Difference between Primary and Candidate Key

Improve
Improve
Like Article
Like
Save
Share
Report

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, Aadhar_ID, F_name, M_name, L_name, Age} 

Here only ID or Aadhar_ID can be primary key because the name, age can be same, but ID or Aadhar_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, Aadhar_ID, F_name, M_name, L_name, Age} 

Here we can see the two candidate keys ID and Aadhar_ID. 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.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 not confirmed that a candidate key can be a primary key.

Last Updated : 21 Feb, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads