A-Z Popular Blog Databases Search »
Technology
 Advertisements
Related Guides

Primary Key vs Candidate Key

 , updated on
A primary key is a field or set of fields that uniquely identifies a row in a table that is explicitly defined with a primary key constraint.
A candidate key is a field or set of fields that uniquely identifies a row in a table.

The Difference

A table can only have one primary key. Tables may have many candidate keys that uniquely identify each row. The primary key is the candidate key that is selected by the data architect and defined as a primary key constraint in a table definition.
It is a good practice to define a primary key for every table and to always use the primary key to relate to a row in a table with a foreign key constraint.
If tables used different candidate keys to relate to a table, maintaining referential integrity might become complex and error prone as rows are deleted and updated.

Example

A table of licensed drivers in a country includes multiple candidate keys such as drivers license number and mobile phone number. The data architect defines a field called ID as a sequence number and defines it as the primary key. This tells all tables in the database to only use ID to relate to rows in the table. When drivers license numbers and mobile phone numbers are updated there is no need to update relations. The ID field never changes and is ideal as a primary key. As the ID is a short sequence number, it is also efficient for use in indexes.
Primary Key vs Candidate Key
Primary Key
Candidate Key
Definition
A field or set of fields that uniquely identifies a row in a table that is explicitly defined with a primary key constraint.
A field or set of fields that uniquely identifies a row in a table.

IT Skills

This is the complete list of articles we have written about it skills.
Algorithms
Analytics
Architecture
Artificial Intelligence
Automation
Big Data
Coding
CRM
Data
Data Mining
Databases
Design
Devops
ERP
Gamification
Information Security
IT Examples
Legacy Software
Office Productivity
Problem Management
Process Automation
Robotics
SCM
Search Applications
Service Delivery
Service Management
SFA
Software Design
Testing
If you enjoyed this page, please consider bookmarking Simplicable.
 

Databases

A list of database terms.

Referential Integrity

An overview of referential integrity with an example.

Atomicity

The definition of atomicity with common examples.

Operational Database

A definition of operational database with examples.

Database Skills

A list of common database skills.

Row vs Column

The difference between row and column explained with examples.

Data

An overview of data with a list of examples.

Types Of Data

The basic types of data.

Dark Data

The definition of dark data with examples.

Data Massage

The mysteries of data massage.

Data Definition

Several useful definitions of data.

Analytics

A definition of analytics with examples.

Data vs Information

The difference between data and information.

Hard Data vs Soft Data

The difference between hard data and soft data.

Human Readable

A definition of human readable.

Data Loss

The common types of data loss.
The most popular articles on Simplicable in the past day.

New Articles

Recent posts or updates on Simplicable.
Site Map