Functional Dependency
Functional Dependency
Functional Dependency
Keys
Definition
• A functional dependency A->B in a relation holds if two tuples having same value of attribute
A also have same value for attribute B.
• Let R be a relation schema
R and R
• The functional dependency
holds on R if and only if for any legal relations r(R), whenever any two tuples t1 and t2 of r agree
on the attributes , they also agree on the attributes . That is,
t1[] = t2 [] t1[ ] = t2 [ ]
• Example: Consider r(A,B ) with the following instance of r.
1 4
1 5
3 7
result := a;
while (changes to result) do
for each in F do
begin
if result then result := result
end
Q4.
FD1 = { STUD_NO->STUD_NAME, STUD_NO->STUD_PHONE,
STUD_NO->STUD_STATE, STUD_NO->STUD_COUNTRY,
STUD_NO -> STUD_AGE, STUD_STATE->STUD_COUNTRY }
Using above functional dependency set FD1, find
{STUD_NO}+ = ?
Q4.
FD1 = { STUD_NO->STUD_NAME, STUD_NO->STUD_PHONE,
STUD_NO->STUD_STATE, STUD_NO->STUD_COUNTRY,
STUD_NO -> STUD_AGE, STUD_STATE->STUD_COUNTRY }
Using above functional dependency set FD1, find
{STUD_NO}+ = {STUD_NO, STUD_NAME, STUD_PHONE, STUD_STATE,
STUD_COUNTRY, STUD_AGE}
Q4.
FD1 = { STUD_NO->STUD_NAME, STUD_NO->STUD_PHONE,
STUD_NO->STUD_STATE, STUD_NO->STUD_COUNTRY,
STUD_NO -> STUD_AGE, STUD_STATE->STUD_COUNTRY }
Using above functional dependency set FD1, find
{STUD_NO}+ = {STUD_NO, STUD_NAME, STUD_PHONE, STUD_STATE,
STUD_COUNTRY, STUD_AGE}
{STUD_STATE}+ = ?
Q4.
FD1 = { STUD_NO->STUD_NAME, STUD_NO->STUD_PHONE,
STUD_NO->STUD_STATE, STUD_NO->STUD_COUNTRY,
STUD_NO -> STUD_AGE, STUD_STATE->STUD_COUNTRY }
Using above functional dependency set FD1, find
{STUD_NO}+ = {STUD_NO, STUD_NAME, STUD_PHONE, STUD_STATE,
STUD_COUNTRY, STUD_AGE}
A. ABCD, φ
B. ABCD, E
C. φ, φ
D. ABC, E
Q5. Let R = ABCDE is a relational scheme with functional dependency
set F = {A → B, B → C, AC → D}. The attribute closures of A and E are
A. ABCD, φ
B. ABCD, E
C. φ, φ
D. ABC, E
KEYS
• Super Key
• Candidate Key
• Primary Key
• Foreign Key
• Alternate Key
• Composite Key
Identifying Super Key and Candidate Key
using Functional Dependencies
• K is a super key for relation schema R if and only if K R
• K is a candidate key for R if and only if
• K R, and
• for no K, R
{STUD_NO, STUD_NAME}+ = ?
Identifying Super Key and Candidate Key
using Functional Dependencies
• K is a super key for relation schema R if and only if K R
• K is a candidate key for R if and only if
• K R, and
• for no K, R
A. V X Y Z
B. V W X Z
C. V W X Y
D. V W X Y Z
Q7. Which of the following is NOT a superkey in a relational schema
with attributes V, W, X, Y, Z and primary key VY ?
A. V X Y Z
B. V W X Z
C. V W X Y
D. V W X Y Z
Q8. Let R = ( A, B, C, D, E, F ) be a relation scheme with the following
dependencies: C→F, E→A, EC→D, A→B. Which of the following is a key
of R?
A. CD
B. EC
C. AE
D. AC
Q8. Let R = ( A, B, C, D, E, F ) be a relation scheme with the following
dependencies: C→F, E→A, EC→D, A→B. Which of the following is a key
of R?
A. CD
B. EC
C. AE
D. AC
Q9. Let x, y, z, a, b, c be the attributes of an entity set E. If {x}, {x,y},
{a,b}, {a,b,c}, {x,y,z} are superkeys then which of the following are the
candidate keys?
Candidate Key = ?
Q12. Finding Candidate Keys and Super Keys of a Relation using FD set F1 =
{E-ID->E-NAME, E-ID->E-CITY, E-ID->E-STATE, E-CITY->E-STATE} .
Ans.
Super Key = {(E-ID), (E-ID, E-NAME), (E-ID, E-CITY), (E-ID, E-STATE), (E-ID, E-
CITY, E-STATE)}
Q16. Let a Relation R have attributes {a1, a2, a3,…, an} and the
candidate key is “a1 a2 a3” then the possible number of super keys?
Ans. ?
Number of Possible Super Keys in DBMS
In general, if we have ‘N’ attributes in a relation and there is one
candidate key with ‘M’ attributes, then the number of possible super
keys are 2(N – M).
Q16. Let a Relation R have attributes {a1, a2, a3,…, an} and the
candidate key is “a1 a2 a3” then the possible number of super keys?
Ans. Possible Super Keys = 2(N-3)
Number of Possible Super Keys in DBMS
Q17. Let a Relation R have attributes {a1, a2, a3,…, an} and the
candidate keys are “a1”, “a2” then the possible number of super keys?
Ans. ?
Number of Possible Super Keys in DBMS
Q17. Let a Relation R have attributes {a1, a2, a3,…, an} and the
candidate keys are “a1”, “a2” then the possible number of super keys?
Ans. Possible Super Keys = (super keys possible with candidate key
A1) + (super keys possible with candidate key A2) – (common super
keys from both A1 and A2)
Possible Super Keys = 2(n-1) + 2(n-1) - 2(n-2)