Identifying Candidate Keys
Identifying candidate keys is an important step in database design and normalization. A candidate key is a minimal set of attributes that can uniquely identify each tuple (row) in a relation.
How to Identify Candidate Keys
Step 1: List all attributes of the relation
Write down all attributes in the relation schema.
Example:
R(A, B, C, D)
Step 2: List the Functional Dependencies (FDs)
Identify all given functional dependencies.
Example:
-
A → B
-
B → C
-
AC → D
Step 3: Find Attribute Closures
Compute the closure of attribute sets using the functional dependencies.
The closure of X (X⁺) is the set of all attributes that can be determined from X.
If X⁺ contains all attributes of the relation, then X is a super key.
Step 4: Find Minimal Super Keys
A candidate key must satisfy two conditions:
-
Uniqueness: It determines all attributes in the relation.
-
Minimality: No attribute can be removed from it.
Remove unnecessary attributes from super keys to obtain minimal keys.
Example 1
Relation:
R(A, B, C, D)
Functional Dependencies:
-
A → B
-
B → C
-
AC → D
Step 1: Compute Closure of A
A⁺ = {A}
A → B ⇒ add B
B → C ⇒ add C
AC → D ⇒ add D
A⁺ = {A, B, C, D}
Since A⁺ contains all attributes, A is a candidate key.
Example 2
Relation:
R(Student_ID, Course_ID, Student_Name, Course_Name, Grade)
Functional Dependencies:
-
Student_ID → Student_Name
-
Course_ID → Course_Name
-
(Student_ID, Course_ID) → Grade
Step 1: Closure of Student_ID
Student_ID⁺ = {Student_ID, Student_Name}
Not all attributes.
Step 2: Closure of Course_ID
Course_ID⁺ = {Course_ID, Course_Name}
Not all attributes.
Step 3: Closure of (Student_ID, Course_ID)
(Student_ID, Course_ID)⁺ =
{Student_ID, Course_ID}
Student_ID → Student_Name
Course_ID → Course_Name
(Student_ID, Course_ID) → Grade
Result:
(Student_ID, Course_ID)⁺ =
{Student_ID, Course_ID, Student_Name, Course_Name, Grade}
So (Student_ID, Course_ID) is the candidate key.
Important Tips for Finding Candidate Keys
1. Attributes not appearing on RHS
Attributes that never appear on the right side of any FD must be part of every candidate key.
Example:
A → B
B → C
Here A must be in the key.
2. Start with minimal attributes
Start closure with attributes that determine many others.
3. Check minimality
If removing any attribute still determines all attributes, it is not minimal.
Example:
If (A,B) is a super key but A alone determines everything, then A is the candidate key.
Summary
A candidate key is:
-
A minimal set of attributes
-
That uniquely identifies tuples
-
Whose closure contains all attributes
Shortcut Method to Identify Candidate Keys
This method helps you quickly find candidate keys without calculating many closures, which is very useful in exams and problem solving.
Step 1: Identify Attributes Not on the RHS
Look at all functional dependencies (FDs) and find attributes that never appear on the Right Hand Side (RHS).
👉 These attributes must be part of every candidate key because nothing determines them.
Example
Relation:
R(A, B, C, D)
FDs:
-
A → B
-
B → C
RHS attributes = B, C
Attributes not on RHS = A, D
So A and D must be included in the candidate key.
Candidate Key → (A, D)
Step 2: Start with Those Attributes
Begin forming a key using the attributes not appearing in RHS.
Then check if they determine all attributes.
Step 3: Add Minimum Extra Attributes if Needed
If the attributes from Step 1 do not determine all attributes, add the minimum additional attribute.
Example 1
Relation:
R(A, B, C, D)
FDs:
-
A → B
-
B → C
-
C → D
Step 1: Find RHS attributes
RHS = B, C, D
Not in RHS = A
Step 2: Check closure
A⁺ =
A → B
B → C
C → D
A⁺ = {A, B, C, D}
✅ Candidate Key = A
Example 2
Relation:
R(A, B, C, D)
FDs:
-
A → B
-
C → D
Step 1: RHS attributes
RHS = B, D
Not in RHS = A, C
Step 2: Start with AC
AC⁺ =
A → B
C → D
AC⁺ = {A, B, C, D}
✅ Candidate Key = (A, C)
Quick Trick
Attributes not appearing on RHS → always part of candidate key
Comments
Post a Comment