SQL Keys are among the most important topics in DBMS and are frequently asked in IBPS SO IT Officer, NIELIT, GATE, UGC NET, and technical interviews. Instead of memorizing definitions, understanding how different keys are related makes it much easier to answer conceptual questions.
This Fast Revision Guide focuses on the most important concepts, high-weightage comparisons, and common exam traps so you can revise the topic in just a few minutes.
Focus on the hierarchy, comparison tables, and exam traps. They cover the majority of SQL Key questions asked in competitive exams.
Quick Revision Cheat Sheet
| Key | Unique | NULL Allowed | Purpose |
|---|---|---|---|
| Super Key | ✅ Yes | Depends | Identify records uniquely |
| Candidate Key | ✅ Yes | ❌ No | Minimal unique identifier |
| Primary Key | ✅ Yes | ❌ No | Main identifier |
| Alternate Key | ✅ Yes | Usually No | Candidate Key not selected |
| Foreign Key | ❌ No | ✅ Yes | Maintain relationships |
| Composite Key | ✅ Yes | ❌ No | Identify records using multiple columns |
Exam Trap: Every Candidate Key is a Super Key, but every Super Key is not a Candidate Key.
Hierarchy of SQL Keys

Understanding this hierarchy is more important than memorizing individual definitions.
Super Key
│
├── Candidate Key
│ │
│ ├── Primary Key
│ └── Alternate Key
│
├── Foreign Key
│
└── Composite Key
Why Are SQL Keys Important?
Imagine an online banking system where:
- Two customers have the same Account Number.
- Transactions refer to accounts that do not exist.
- Customer records cannot be uniquely identified.
Such a database would become inconsistent and unreliable.
SQL Keys solve these problems by:
- Uniquely identifying records.
- Eliminating ambiguity.
- Maintaining relationships between tables.
- Enforcing data integrity.
- Improving database performance and consistency.
1. Super Key
A Super Key is a column or a combination of columns that can uniquely identify every row in a table.
A Super Key may contain extra attributes that are not required for uniqueness.
Example
Consider the following table:
| StudentID | Aadhaar | Name | |
|---|---|---|---|
| 101 | rahul@gmail.com | 1234 | Rahul |
| 102 | priya@gmail.com | 5678 | Priya |
Possible Super Keys include:
- StudentID
- Aadhaar
- StudentID + Name
- Email + Name
- StudentID + Email
Notice that StudentID + Name is still unique, even though Name is unnecessary.
Important Points
- Every Candidate Key is a Super Key.
- A Super Key may contain extra columns.
- There can be many Super Keys in a table.
- The smallest Super Keys become Candidate Keys.
A Super Key guarantees uniqueness, but it is not necessarily the most efficient choice because it may include unnecessary attributes.
2. Candidate Key
A Candidate Key is the smallest possible Super Key that uniquely identifies each row.
Unlike a Super Key, it contains no unnecessary attributes.
Example
Suppose the following attributes are unique:
- StudentID
- Aadhaar
Then all three are Candidate Keys because each one alone uniquely identifies a student.
However:
StudentID + Name
is not a Candidate Key because Name is unnecessary.
Important Points
- Every Candidate Key is unique.
- A table can have multiple Candidate Keys.
- Candidate Keys contain the minimum number of attributes required for uniqueness.
- One Candidate Key is later selected as the Primary Key.
Super Key vs Candidate Key
| Feature | Super Key | Candidate Key |
|---|---|---|
| Unique | ✅ | ✅ |
| Extra Attributes | May contain | No |
| Minimal | ❌ | ✅ |
| Number per Table | Many | One or More |
Memory Trick: Think of a Candidate Key as the "best" Super Key because it achieves uniqueness without carrying unnecessary columns.
3. Primary Key
A Primary Key is the Candidate Key chosen to uniquely identify every row in a table.
Every table can have only one Primary Key, although that Primary Key may consist of multiple columns (Composite Primary Key).
Syntax
CREATE TABLE Student (
StudentID INT PRIMARY KEY,
Name VARCHAR(50),
Email VARCHAR(100)
);
Example
| StudentID | Name | |
|---|---|---|
| 101 | Rahul | rahul@gmail.com |
| 102 | Priya | priya@gmail.com |
| 103 | Amit | amit@gmail.com |
The StudentID uniquely identifies every record.
Characteristics of a Primary Key
- Must contain unique values.
- Cannot contain NULL values.
- Only one Primary Key constraint is allowed per table.
- Automatically enforces UNIQUE and NOT NULL.
- Used to establish relationships with other tables.
Candidate Key vs Primary Key
| Candidate Key | Primary Key |
|---|---|
| One or more may exist | Only one per table |
| All are eligible to become Primary Key | Selected from Candidate Keys |
| Not all Candidate Keys are chosen | Used as the main identifier |
Exam Tip
Many students think:
Every unique column automatically becomes the Primary Key.
This is incorrect.
A Primary Key is selected from the available Candidate Keys.
Other Candidate Keys become Alternate Keys, which we'll discuss next.
Exam Trap: A table may have many Candidate Keys but only one Primary Key.
Quick Summary
| Key | Purpose | Unique | NULL |
|---|---|---|---|
| Super Key | Identify rows | ✅ | Depends |
| Candidate Key | Minimal unique identifier | ✅ | ❌ |
| Primary Key | Main identifier | ✅ | ❌ |
Revise SQL Constraints
SQL Constraints and SQL Keys are closely related. Strengthen your concepts before moving to SQL Joins.
4. Alternate Key
An Alternate Key is a Candidate Key that was not selected as the Primary Key.
In simple words:
Primary Key = Selected Candidate Key
Alternate Key = Remaining Candidate Keys
Example
Consider the following table:
| StudentID | Aadhaar | Name | |
|---|---|---|---|
| 101 | rahul@gmail.com | 123456789012 | Rahul |
| 102 | priya@gmail.com | 987654321098 | Priya |
Here:
- StudentID → Candidate Key ✅ (Selected as Primary Key)
- Email → Candidate Key ✅ (Alternate Key)
- Aadhaar → Candidate Key ✅ (Alternate Key)
Important Points
- Alternate Keys are unique.
- Multiple Alternate Keys can exist.
- They are Candidate Keys that were not chosen as the Primary Key.
Remember: Every Alternate Key is a Candidate Key, but not every Candidate Key is an Alternate Key.
5. Foreign Key
A Foreign Key is a column (or group of columns) that creates a relationship between two tables.
It references the Primary Key (or another UNIQUE key) of another table and helps maintain Referential Integrity.
Example
Department Table (Parent)
| DepartmentID | DepartmentName |
|---|---|
| 10 | Computer Science |
| 20 | Information Technology |
Student Table (Child)
| StudentID | Name | DepartmentID |
|---|---|---|
| 101 | Rahul | 10 |
| 102 | Priya | 20 |
The value of DepartmentID in the Student table must already exist in the Department table.
Syntax
CREATE TABLE Department(
DepartmentID INT PRIMARY KEY,
DepartmentName VARCHAR(50)
);
CREATE TABLE Student(
StudentID INT PRIMARY KEY,
Name VARCHAR(50),
DepartmentID INT,
FOREIGN KEY (DepartmentID)
REFERENCES Department(DepartmentID)
);
Important Points
- Maintains relationships between tables.
- Prevents invalid references.
- Duplicate values are allowed.
- NULL values are generally allowed unless restricted separately.
- Multiple Foreign Keys can exist in a table.
Remember: A PRIMARY KEY enforces Entity Integrity, while a FOREIGN KEY enforces Referential Integrity.
6. Composite Key
A Composite Key is a key formed by combining two or more columns to uniquely identify a record.
It is useful when a single column cannot uniquely identify each row.
Example
CREATE TABLE Enrollment(
StudentID INT,
CourseID INT,
PRIMARY KEY(StudentID, CourseID)
);
Neither StudentID nor CourseID is unique individually.
However,
(StudentID, CourseID)
uniquely identifies each enrollment record.
Important Points
- Combines multiple columns.
- Used when one column is insufficient.
- A Composite Primary Key is still one Primary Key constraint.
Exam Trap: A Composite Primary Key does not mean multiple Primary Keys. A table can have only one PRIMARY KEY constraint.
High-Weightage Comparison Tables
Super Key vs Candidate Key
| Feature | Super Key | Candidate Key |
|---|---|---|
| Uniquely identifies rows | ✅ | ✅ |
| Contains extra attributes | May contain | No |
| Minimal | ❌ | ✅ |
| Number per table | Many | One or More |
Candidate Key vs Primary Key
| Candidate Key | Primary Key |
|---|---|
| Many can exist | Only one per table |
| Eligible to become Primary Key | Selected Candidate Key |
| All Candidate Keys are unique | Always unique |
Primary Key vs Foreign Key
| Primary Key | Foreign Key |
|---|---|
| Identifies records | Creates relationships |
| Unique | May contain duplicates |
| Cannot contain NULL | Can contain NULL |
| One per table | Multiple allowed |
| Entity Integrity | Referential Integrity |
Primary Key vs Alternate Key
| Primary Key | Alternate Key |
|---|---|
| Chosen Candidate Key | Remaining Candidate Keys |
| One per table | Multiple allowed |
| Main identifier | Secondary unique identifiers |
SQL Keys Hierarchy (Quick Revision)
Super Key
│
├── Candidate Key
│ │
│ ├── Primary Key
│ └── Alternate Key
│
├── Foreign Key
│
└── Composite Key
Memory Tricks
Hierarchy
Super
↓
Candidate
↓
Primary
↓
Alternate
Think of it as a filtering process:
- Every Primary Key is a Candidate Key.
- Every Candidate Key is a Super Key.
Foreign Key
Foreign Key
↓
Relationship
↓
Referential Integrity
Common Exam Traps
These conceptual questions are frequently asked in competitive exams.
Trap 1
Can a table have multiple Candidate Keys?
✅ Yes
Trap 2
Can a table have multiple Primary Keys?
❌ No
Trap 3
Can a Primary Key be Composite?
✅ Yes
Trap 4
Can a Foreign Key contain duplicate values?
✅ Yes
Trap 5
Can a Foreign Key contain NULL values?
✅ Yes, unless restricted by a NOT NULL constraint.
Trap 6
Is every Candidate Key a Super Key?
✅ Yes
Trap 7
Is every Super Key a Candidate Key?
❌ No
Trap 8
Can a Foreign Key reference a UNIQUE key?
✅ Yes
A Foreign Key can reference a PRIMARY KEY or another column (or set of columns) with a UNIQUE constraint, provided it uniquely identifies rows.
Trap 9
Can a Composite Key consist of three columns?
✅ Yes
A Composite Key can contain two or more columns.
Trap 10
Can a table exist without a Primary Key?
✅ Yes
Although a Primary Key is strongly recommended, SQL does not require every table to have one.
One-Page Revision Sheet
| Key | Unique | NULL Allowed | Main Purpose |
|---|---|---|---|
| Super Key | ✅ | Depends | Uniquely identify records |
| Candidate Key | ✅ | ❌ | Minimal unique identifier |
| Primary Key | ✅ | ❌ | Main identifier |
| Alternate Key | ✅ | Depends | Candidate Key not selected |
| Foreign Key | ❌ | ✅ | Maintain relationships |
| Composite Key | ✅ | ❌ | Multi-column identifier |
🎯 Revision Checklist
Tick the concepts you're confident about before attempting the mock test.
What to Study Next
Strengthen your DBMS concepts with these related articles.
| Topic | Status |
|---|---|
| SQL Commands | ✅ Available |
| SQL Constraints | ✅ Available |
| SQL Joins | 🚧 Coming Soon |
| Normalization | 🚧 Coming Soon |
| ACID Properties | 🚧 Coming Soon |
| Transactions | 🚧 Coming Soon |
Ready to Test Your SQL Keys Knowledge?
Attempt a topic-wise SQL Keys mock test with exam-level questions, detailed explanations, and performance analysis.
