Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Candidate Key in RDBMS
A Candidate Key is a minimal set of attributes that can uniquely identify each row in a table. Each table may have one or more candidate keys, and one of them is chosen as the Primary Key. A candidate key is essentially a minimal super key − no attribute can be removed from it without losing uniqueness.
Example 1: Employee Table
In an Employee table, both EmployeeID and EmployeeEmail can uniquely identify each employee. Therefore both are candidate keys. You select any one of them as the primary key, since a table can have only a single primary key.
Example 2: Student Table
Consider the following Student table ?
| Student_ID | Student_Enroll | Student_Name | Student_Email |
|---|---|---|---|
| S02 | 4545 | Dave | ddd@gmail.com |
| S34 | 4541 | Jack | jjj@gmail.com |
| S22 | 4555 | Mark | mmm@gmail.com |
Here, Student_ID, Student_Enroll, and Student_Email are the candidate keys because each one can uniquely identify a student record on its own. Student_Name is not a candidate key because names can be duplicated.
Candidate Keys:
{Student_ID} ? unique for each student
{Student_Enroll} ? unique enrollment number
{Student_Email} ? unique email address
NOT a Candidate Key:
{Student_Name} ? names can repeat (not unique)
Primary Key (choose one): Student_ID
Key Properties
- A candidate key must be unique for every row.
- A candidate key must be minimal − no attribute can be removed without losing uniqueness.
- A candidate key cannot contain NULL values.
- One candidate key is selected as the Primary Key; the remaining are called Alternate Keys.
Conclusion
A candidate key is any minimal set of attributes that can uniquely identify each row in a table. A table can have multiple candidate keys, but only one is chosen as the primary key. The rest become alternate keys that can still be used for unique constraints and indexing.
