Attribute Closure (XβΊ)
Attribute Closure of a set X is the set of all attributes that can be determined from X using functional dependencies.
π XβΊ = all attributes that X can determine (direct + indirect)
Formula: XβΊ = { A | X β A }
π― Why Attribute Closure is Important?
- Find Super Keys & Candidate Keys
- Check Functional Dependencies
- Used in Normalization
- Helps in Minimal Cover
π If XβΊ contains all attributes β X is a Super Key
Learn more about
Super Key
βοΈ Steps to Find Attribute Closure
- Start with XβΊ = X
- Check all Functional Dependencies
- If LHS β XβΊ β add RHS
- Repeat until no change occurs
π Continue until closure stops growing
π Example (GATE Level)
R(A, B, C, D, E)
F = { A β BC, B β D, CD β E }
AβΊ = {A}
β {A, B, C}
β {A, B, C, D}
β {A, B, C, D, E}
Final: AβΊ = {A, B, C, D, E}
π A is a Super Key
π Attribute Closure Example (GATE Level)
Given Functional Dependencies:
F = { A β B, C β D, AB β E, BE β C, EF β G }
---
π― Goal
Find the following closures:
---
βοΈ Step-by-Step Rule
π Start with given attributes β keep adding new attributes using FDs until no change
---
π Find AβΊ
Start: AβΊ = {A}
AβΊ = {A, B}
No more dependencies can be applied
π AβΊ = {A, B}
---
π Find AFβΊ
Start: AFβΊ = {A, F}
- A β B β add B
- AB β E β add E
- BE β C β add C
- C β D β add D
- EF β G β add G
AFβΊ = {A, F, B, E, C, D, G}
π AFβΊ = {A, B, C, D, E, F, G}
---
π Find AEβΊ
Start: AEβΊ = {A, E}
- A β B β add B
- BE β C β add C
- C β D β add D
AEβΊ = {A, E, B, C, D}
π AEβΊ = {A, B, C, D, E}
---
π Find CDβΊ
Start: CDβΊ = {C, D}
- C β D (already present)
CDβΊ = {C, D}
No new attribute can be added
π CDβΊ = {C, D}
---
π£ Final Answer
- AβΊ = {A, B}
- AFβΊ = {A, B, C, D, E, F, G}
- AEβΊ = {A, B, C, D, E}
- CDβΊ = {C, D}
π AFβΊ gives all attributes β AF is a candidate key
Learn more about
Candidate Key
π§ Key Observations
- Closure only increases (monotonic)
- Order of FD application does not matter
- Captures indirect (transitive) dependencies
β Common Mistakes
- Ignoring transitive dependencies
- Stopping early
- Not rechecking after adding attributes
Prime and Non-Prime Attributes (Deep Concept)
In DBMS, attributes are classified based on their participation in candidate keys.
This concept is extremely important for normalization (2NF, 3NF, BCNF).
1. Prime Attribute
A prime attribute is any attribute that is part of at least one candidate key.
π If an attribute appears in ANY candidate key β it is PRIME
Example 1
- Relation: R(A, B, C)
- Candidate Keys: (A, B) and (A, C)
π Prime Attributes = A, B, C
β οΈ Important: Even if an attribute appears in only one candidate key, it is still PRIME.
2. Non-Prime Attribute
A non-prime attribute is an attribute that is NOT part of any candidate key.
π If attribute is NOT in any candidate key β NON-PRIME
Example 2
- Relation: R(A, B, C, D)
- Candidate Key: (A, B)
π Prime = A, B
π Non-Prime = C, D
π₯ Tricky GATE Concept
If a relation has multiple candidate keys, then all attributes appearing in any candidate key are PRIME.
- Relation: R(A, B, C)
- Candidate Keys: (A, B) and (B, C)
π Prime = A, B, C
π Non-Prime = None
π‘ GATE Trick: If all attributes are part of some candidate key β No non-prime attributes
Relation with Functional Dependency
Functional Dependency helps identify candidate keys, and candidate keys determine prime attributes.
- Find closure β find candidate key
- Candidate key β identify prime attributes
π₯ Role in Normalization
β‘οΈ Second Normal Form (2NF)
A relation is in 2NF if:
- It is in 1NF
- No partial dependency of NON-PRIME attribute on candidate key
π Partial dependency = Non-prime depends on part of key
β‘οΈ Third Normal Form (3NF)
A relation is in 3NF if:
- No transitive dependency
- Non-prime attribute should not depend on another non-prime
π X β Y allowed if Y is PRIME
π GATE-Level Question Example
Relation: R(A, B, C, D)
FD: A β B, B β C
Step 1: Find candidate key
π A+ = A, B, C β Not complete
π Add D β (A, D) is candidate key
π Prime = A, D
π Non-Prime = B, C
Difference Table
| Prime Attribute |
Non-Prime Attribute |
| Part of candidate key |
Not part of candidate key |
| Used in normalization rules |
Causes dependency issues |
| Helps identify records |
Stores extra data |
π Final Shortcut:
Candidate Key ke andar β PRIME
Candidate Key ke bahar β NON-PRIME