Difference Between Primary and Candidate Key

In this post, we will understand the difference between primary key and the candidate key.

Primary Key

  • It is used to ensure that the data in the specific column is unique.

  • It helps uniquely identify a record in a relational database.

  • One primary key only is allowed in a table.

  • It is a combination of the ‘UNIQUE’ and ‘Not Null’ constraints.

  • This means it can’t be a NULL value.

  • It is the most important part of a table.

  • It is a candidate key.

  • Its value can’t be deleted from parent table.

  • The constraint can be implicitly defined for the temporary tables.

Candidate key

  • It can have NULL value.

  • It may or may not have a primary key.

  • It tells about which key can be used as a primary key.

  • It is a unique key that helps identify a record uniquely in a table.

  • A table can have multiple candidate keys.