Open In App

Functional Dependency and Attribute Closure

Fundamental ideas in database management and design are functional dependency and attribute closure. They are essential to maintaining data integrity and building effective, organized, and normalized databases.

Functional Dependency

A functional dependency A->B in a relation holds if two tuples having the same value of attribute A also have the same value for attribute B. For Example, in relation to STUDENT shown in Table 1, Functional Dependencies 



STUD_NO->STUD_NAME, STUD_NO->STUD_PHONE hold

but 

STUD_NAME->STUD_STATE do not hold

Student Table

Advantages of Functional Dependencies

Disadvantages of Functional Dependencies

How to find Functional Dependencies for a Relation?

Functional Dependencies in a relation are dependent on the domain of the relation. Consider the STUDENT relation given in Table 1. 



Functional Dependency Set

Functional Dependency set or FD set of a relation is the set of all FDs present in the relation. For Example, FD set for relation STUDENT shown in table 1 is: 
 

 { STUD_NO->STUD_NAME, STUD_NO->STUD_PHONE, STUD_NO->STUD_STATE, STUD_NO->STUD_COUNTRY, 
STUD_NO -> STUD_AGE, STUD_STATE->STUD_COUNTRY }

Attribute Closure

Attribute closure of an attribute set can be defined as set of attributes which can be functionally determined from it. 

How to find attribute closure of an attribute set?

To find attribute closure of an attribute set: 

Using FD set of table 1, attribute closure can be determined as: 

(STUD_NO)+ = {STUD_NO, STUD_NAME, STUD_PHONE, STUD_STATE, STUD_COUNTRY, STUD_AGE}
(STUD_STATE)+ = {STUD_STATE, STUD_COUNTRY}

Advantages of Attribute Closure

Disadvantages of Attribute Closure

How to Find Candidate Keys and Super Keys Using Attribute Closure?

(STUD_NO, STUD_NAME)+ = {STUD_NO, STUD_NAME, STUD_PHONE, STUD_STATE, STUD_COUNTRY, STUD_AGE} 

(STUD_NO)+ = {STUD_NO, STUD_NAME, STUD_PHONE, STUD_STATE, STUD_COUNTRY, STUD_AGE} 

(STUD_NO, STUD_NAME) will be super key but not candidate key because its subset (STUD_NO)+ is equal to all attributes of the relation. So, STUD_NO will be a candidate key

Prime and Non-Prime Attributes

Attributes which are parts of any candidate key of relation are called as prime attribute, others are non-prime attributes. For Example, STUD_NO in STUDENT relation is prime attribute, others are non-prime attribute. 

Conclusion

Tools like functional dependency and attribute closure are helpful when designing and optimizing databases. They are useful for:

GATE Questions

Q.1: Consider the relation scheme R = {E, F, G, H, I, J, K, L, M, N} and the set of functional dependencies {{E, F} -> {G}, {F} -> {I, J}, {E, H} -> {K, L}, K -> {M}, L -> {N} on R. What is the key for R? (GATE-CS-2014) 

A. {E, F} 
B. {E, F, H} 
C. {E, F, H, K, L} 
D. {E} 

Solution:

Finding attribute closure of all given options, we get: 
{E,F}+ = {EFGIJ} 
{E,F,H}+ = {EFHGIJKLMN} 
{E,F,H,K,L}+ = {{EFHGIJKLMN} 
{E}+ = {E} 
{EFH}+ and {EFHKL}+ results in set of all attributes, but EFH is minimal. So it will be candidate key. So correct option is (B). 

Q.2: How to check whether an FD can be derived from a given FD set?

Solution:

To check whether an FD A->B can be derived from an FD set F, 
 

  1. Find (A)+ using FD set F.
  2. If B is subset of (A)+, then A->B is true else not true.

Q.3: In a schema with attributes A, B, C, D and E following set of functional dependencies are given 
{A -> B, A -> C, CD -> E, B -> D, E -> A} 
Which of the following functional dependencies is NOT implied by the above set? (GATE IT 2005) 

A. CD -> AC 
B. BD -> CD 
C. BC -> CD 
D. AC -> BC 

Solution:

Using FD set given in question, 
(CD)+ = {CDEAB} which means CD -> AC also holds true. 
(BD)+ = {BD} which means BD -> CD can’t hold true. So this FD is no implied in FD set. So (B) is the required option. 
Others can be checked in the same way. 

Q.4: Consider a relation scheme R = (A, B, C, D, E, H) on which the following functional dependencies hold: {A–>B, BC–> D, E–>C, D–>A}. What are the candidate keys of R? [GATE 2005] 

(a) AE, BE 
(b) AE, BE, DE 
(c) AEH, BEH, BCH 
(d) AEH, BEH, DEH 

Solution:

(AE)+ = {ABECD} which is not set of all attributes. So AE is not a candidate key. Hence option A and B are wrong. 
(AEH)+ = {ABCDEH} 
(BEH)+ = {BEHCDA} 
(BCH)+ = {BCHDA} which is not set of all attributes. So BCH is not a candidate key. Hence option C is wrong. 
So correct answer is D. 


Article Tags :