Functional Dependancy ABES
Functional Dependancy ABES
Functional Dependency
(Module 4)
This document contains valuable confidential and proprietary information of ABESEC. Such confidential and
proprietary information includes, amongst others, proprietary intellectual property which can be legally protected and
commercialized. Such information is furnished herein for training purposes only. Except with the express prior
written permission of ABESEC, this document and the information contained herein may not be published,
disclosed, or used for any other purpose.
2
Copyright © 2021, ABES Engineering College
Session Plan
Introduction to Functional Dependency
Attribute Closure
Functional Dependency
A good relation (table) design is one, which has minimum redundancy and minimum
data dependency among the attributes of the relation (table).
By minimizing the data dependency, we reduce the number of anomalies that may
occur when the database is used.
Functional dependency is one of the core concept in the relational database design
theory
In this unit we will study the concept of functional dependency, key identification using
functional dependencies, the equivalency of functional dependencies sets, and
canonical cover
5
Copyright © 2021, ABES Engineering College
Functional dependency in a relation (table)
6
Copyright © 2021, ABES Engineering College
Process to identify Functional Dependencies in
a given relation
What kind of dependencies can we observe among the attributes in Relation
R?
A→B, A→C, A→D, A→E (these are true as A is a key and unique for all
tuples)
B→C (this is not true, as t1.B = t2.B but t1.C ≠ t2.C)
B→D (this is not true, as t1.B = t2.B but t1.D ≠ t2.D)
B→E (this is true, as t1.B = t2.B and t1.E = t2.E & t3.B = t4.B and t3.E = t4.E)
C→D (this is true, as t1.C = t3.C and t1.D = t3.D & t2.C = t4.C and t2.D = t4.D)
C→E (this is true, as t1.C = t3.C and t1.E = t3.E & t2.C = t4.C and t2.E = t4.E)
D→C (this is not true, as t1.D = t3.D = t5.D but t1.C = t3.C ≠ t5.C)
BC→D, BC→E, BC→A (these are true as BC is a key and unique for all
tuples)
BD→E, BD→C, BD→A (these are true as BD is a key and unique for all
tuples)
We can use the above process to identify various functional dependencies in
the given Relation.
7
Copyright © 2021, ABES Engineering College
Functional Dependency- Example
Example
Assume we have an employee relation with attributes: EMPLOYEE
E-ID, E-NAME, E-CITY, E-STATE. Relation/Table
E-ID attribute can uniquely identify (determine) the E- E-
E-ID E-NAME E-CITY
NAME attribute of employee table because if we know the STATE
E-ID, we can tell that employee name associated with it. E001 John Delhi Delhi
Functional dependency can be written as: E002 Mary Delhi Delhi
E-ID → E-NAME E003 John Noida U.P.
We can say that E-NAME is functionally dependent on E-ID.
Can we say
E-NAME -> E-CITY
E-CITY -> E-STATE
roll_no of the student can uniquely identify the first_name, middle_name, dob, gender etc.. of a student. The
functional dependency can be written as:
Roll_no → first_name
Roll_no → dob
Roll_no → gender
One more functional dependency exists in the above Relation: city → state
Can we say: city → pincode, from the current relation instance, we can say that this functional dependency
exists, however from a database design perspective, this might be a wrong assumption as bigger cities can
have multiple pin codes within them.
9
Copyright © 2021, ABES Engineering College
Question on FD (GATE 2002)
Q. From the following instance of a relation schema R(A,B,C) we can conclude that:
From the relational instance given, we may strike out FD s that
do not hold. e.g. B does not functionally determine C(This is
true). But we cannot say that A functionally determines B for
the entire relation itself. This is because that, A->B holds for
this instance, but in future there might be some tuples added to
the instance that may violate A->B. So overall on the relation
we cannot conclude that A->B, from the relational instance which
is just a subset of an entire relation
13
Copyright © 2021, ABES Engineering College
Question on FD(GATE-2000)
14
Copyright © 2021, ABES Engineering College
Question on FD(GATE 2005)
Q. In a schema with attributes A, B, C, D and E, following set of functional
dependencies are given:
F={A->B,A->C,CD->E,B->D,E->A}
Which of the following functional dependencies is NOT implied by the above set?
A. CD->AC
B. BD->CD
C. BC->CD
D. AC->BC
15
Copyright © 2021, ABES Engineering College
Question on FD(GATE 2005)
Q. In a schema with attributes A, B, C, D and E, following set of functional
dependencies are given:
F={A->B,A->C,CD->E,B->D,E->A}
Which of the following functional dependencies is NOT implied by the above set?
A. CD->AC
B. BD->CD
C. BC->CD
D. AC->BC
16
Copyright © 2021, ABES Engineering College
Quality Content for Outcome based Learning
16
Copyright © 2021, ABES Engineering College
Trivial Functional Dependency
In Trivial Functional Dependency, a dependent is always a subset of the determinant. i.e.,
If X→Y, and Y is the subset of X, it is called trivial functional dependency.
Trivial Functional Dependency occurs in a Composite Primary Key.
Each attribute has a trivial functional dependency on itself.
19
Copyright © 2021, ABES Engineering College
Non-trivial Functional Dependency
In Non-trivial functional dependency, the dependent is strictly not a subset of the determinant. i.e., If
X→Y, and Y is not a subset of X, then it is called Non-trivial functional dependency.
dept_id → dept_name is a non-trivial functional dependency, since the dependent dept_name is not
a subset of determinant dept_id.
Similarly, (dept_id, dept_name) → dept_location is also a non-trivial functional dependency, since
dept_location is not a subset of (dept_id, dept_name).
20
Copyright © 2021, ABES Engineering College
Transitive Functional Dependency
In transitive functional dependency, the dependent is indirectly dependent on the determinant. i.e., If
X→Y, there exists a set of attributes Z in the Relation that is not a Candidate Key and both X→Z and
Z→Y hold, thus Y is transitively dependent on X.
A transitive dependency can only occur in a Relation of three or more attributes.
21
Copyright © 2021, ABES Engineering College
Transitive Functional Dependency…
Let’s assume a student relation as below.
A. A->C
B. B->D
C. BC->D A->C can be implied by A->BC and
D. All of the above BC->D can be implied by C->D. But
we can not get B->D sing given
functional dependencies.
Option (B) is correct.
A multivalued dependency (MVD) X —>> Y specified on relation schema R, where X and Y are
both subsets of R, specifies the following constraint on any relation state r of R: If two tuples t1 and t2
exist in r such that t1[X] = t2[X], then two tuples t3 and t4 should also exist in r with the following
properties, where we use Z to denote (R - (X υ Y)):
t3[X] = t4[X] = t1[X] = t2[X].
t3[Y] = t1[Y] and t4[Y] = t2[Y].
t3[Z] = t2[Z] and t4[Z] = t1[Z].
As per the formal definition of a relation, an attributes can hold only atomic values, hence the
above relation is in-valid and needs be converted as below
roll_no name sport
191306280 Aayushi Tennis
191306280 Aayushi Basketball
In above relation Trivial Multivalued dependency occurs because there is one multivalued
attribute i.e, sports.
29
Copyright © 2021, ABES Engineering College
Armstrong’s Axioms in Functional Dependency in DBMS
Example:
X = {a, b, c, d, e}
Y = {a, b, c}
Example:
For R(ABCD), if A → B then AC → BC
Example:
if (X→Y & Y→Z) then X→Z
Proof:
1. X → Y (given)
2. X → Z (given)
3. X → XY (using Augmentation Rule on 1 by augmentation with X. Where XX = X)
4. XY → YZ (using Augmentation Rule on 2 by augmentation with Y)
5. X → YZ (using Transitive Rule on 3 and 4)
Proof:
1. X → YZ (given)
2. YZ → Y (using Reflexivity Rule)
3. X → Y (using Transitive Rule on 1 and 2)
Proof,
1. P → Q (Given)
2. A → B (Given)
3. PA → QA (Augmentation of 1 and A)
4. PA → Q (Decomposition of 3)
5. PA → PB (Augmentation of 2 and P)
6. PA → B (Decomposition of 5)
7. PA → QB (Union 4 and 6)
Proof:
1. X → Y (given)
2. WY → Z (given)
3. WX → WY (using Augmentation Rule on 1 by augmenting with W)
4. WX → Z (using Transitive Rule on 3 and 2)
Example:- let us consider the set F of functional dependencies for Relation R (A,B,C,D); F =
{A→B, AD→B}. In this case, the FD A→B is full functional dependency whereas AD→B is partial
functional dependency; i.e., B is not fully functionally dependent on AD; instead, it depends on A
alone.
The set of attributes that are functionally dependent on attribute A is called the
attribute closure of A and it can be represented as A+.
41
Copyright © 2021, ABES Engineering College
Attribute Closure…
Example - Find the attribute closures of Relation R(A,B,C,D,E) with functional dependency (FD) set F =
{AB→C, B→D, C→E, D→A}
To find B+, we will add an attribute in the set using various FD, which has been shown in steps below:
B+ = {B,D,A,C}
We can find (C, D)+ by adding C and D into the set (triviality) and then E using(C→E) and then A using (D→A)
(C,D)+ = {C,D,E,A}
Similarly, we can find (B, C)+ by adding B and C into the set (triviality) and then D using (B→D) and then E using
(C→E) and then A using (D→A)
(BC)+ = {B,C,D,E,A}
A. ABCD, φ
B. ABCD, E
C. Φ, φ
D. ABC, E
43
Copyright © 2021, ABES Engineering College
Closure of a Set of Functional Dependencies
Procedure to compute F+
F+=F
repeat
for each functional dependency f in F+
apply reflexive and augmentation rules on f
add the resulting dependencies to F+
for each pair of functional dependencies f1 and f2 in F+
if f1 and f2 can be combined using transitivity
add the resulting function dependencies to F+
Until F+ does not change any further
44
Copyright © 2021, ABES Engineering College
Example for finding FD closure
45
Copyright © 2021, ABES Engineering College
Identifying Keys in a Relation by using
Attribute Closure
Definition of Super Key and Candidate Key (revisiting)
Super Key - It is a set of attributes of a relation that can be used to identify a tuple uniquely.
Candidate Key - It is a minimal set of attributes of a relation that can be used to identify a tuple uniquely.
Let us find the Super Keys of Relation R(A,B,C,D,E) with FD set F = {AB→C, B→E, C→D}
Now let us find attribute closure of all attributes individually and in combination to find the other possible
Super Keys.
In the above Relation R(A, B, C, D, E), we will have 25-1 = 31 possible combinations, which can be Super Keys.
For example –
Super Key {A,B,C,D,E} – attribute {A,B} is a proper subset of this Super Key and it is itself a Super Key,
so {A,B,C,D,E} can’t be a Candidate Key
Super Key {A,B,C,E} - attribute {A,B} is a proper subset of this Super Key and it is itself a Super Key, so
{A,B,C,E} can’t be a Candidate Key
Super Key {A,B,D} - attribute {A,B} is a proper subset of this Super Key and it is itself a Super Key, so
{A,B,D} can’t be a Candidate Key
Super Key {A,B} - attribute {A} & {B} are proper subset of this Super Key, but neither {A} nor {B} is itself
a Super Key, so {A,B} is a Candidate Key
So (A,B) is Candidate Key for Relation R(A,B,C,D,E) with FD set F = {AB→C, B→E, C→D}
The attributes of a Relation that are part of Candidate Keys are called Prime
Attributes, and the remaining attributes are called Non-Prime Attributes.
In Relation R(A,B,C,D,E) with FD set F = {AB→C, B→E, C→D},
(A,B) is Candidate Key, therefore,
(A),(B) – Prime Attributes
(D),(C),(E) – Non-Prime Attributes
Therefore the given Relation has two Candidate Keys – (BC) & (DC)
Therefore the given Relation has two Candidate Keys – (AC) & (BC)
1. Calculate the closure of LHS (left-hand side) in FD2, for each FD in FD2,
with respect to FDs in FD1. If the closure includes the attributes on the RHS
(right-hand side), this FD will hold in FD1.
2. If this is the case for every FD in FD2, then FD1 covers FD2.
3. We determine whether FD2 and FD1 are equivalent by checking that FD2
covers FD1 and FD1 covers FD2 by using the above process.
Find closure of LHS all FDs in FD2, with respect to FDs in FD1, and see if the closure returns the
attributes on RHS.
(A)+ = {A,C,D} – the closure includes (C) & (D), thus A→CD holds in FD1 also.
(E)+ = {E,A,D,H} – the closure includes (A) & (H), thus E→AH holds in FD1 also.
As we can see that all FDs of FD2 hold in FD1 also; thus, FD1 covers FD2 (FD1 ⊃ FD2)
As, FD1 covers FD2 (FD1 ⊃ FD2) & FD2 covers FD1 (FD2 ⊃ FD1), therefore FD1 is equivalent to
FD2 (FD1 = FD2).
A. P is a subset of Q
B. Q is a subset of P
C. P=Q
D. P≠Q
A. P is a subset of Q
B. Q is a subset of P
C. P=Q
D. P≠Q
69
Copyright © 2021, ABES Engineering College
MCQ’S
A. P is a subset of Q
B. Q is a subset of P
C. P=Q
D. P≠Q
70
Copyright © 2021, ABES Engineering College
MCQ’S
A. P is a subset of Q
B. Q is a subset of P
C. P=Q
D. P≠Q
71
Copyright © 2021, ABES Engineering College
Canonical Cover or Minimal Set of Functional
Dependency
We can define a set of functional dependencies FD to be minimal (canonical cover) if it
satisfies the following conditions:
1. Every dependency in FD has a single attribute for its right-hand side.
2. We cannot remove any dependency from FD and still have a set of dependencies
equivalent to FD.
3. On the left-hand side (LHS) of any functional dependency (FDs remaining after
condition two is met), we should not have any extraneous attribute (applicable when
LHS has more than one attribute). An attribute of a functional dependency is
extraneous if we can remove it without changing the closure of the set of functional
dependencies.
Condition 1
Given FD = {B→A, AD→BC, C→ABD} to be decomposed using Armstrong Axiom’s decomposition rule.
B→A
AD→B ( using decomposition inference rule on AD→BC)
AD→C ( using decomposition inference rule on AD→BC)
C→A ( using decomposition inference rule on C→ABD)
C→B ( using decomposition inference rule on C→ABD)
C→D ( using decomposition inference rule on C→ABD)
Now set of FD = {B→A, AD→B, AD→C, C→A, C→B, C→D}
Since the (AD)+, (A)+, (D)+ that we found are not all equivalent, hence in FD AD→C, both A and D are
important attributes and cannot be removed.
Hence resultant FD = {B→A, AD→C, C→B, C→D} and we can rewrite as
FD = {B→A, AD→C, C→BD} is Canonical Cover of FD = {B→A, AD→BC, C→ABD}.
Condition 1
Given FD = {V→W, VW→X, Y→VXZ} to be decomposed using Armstrong Axiom’s decomposition rule.
V→W
VW→X
Y→V ( using decomposition inference rule on Y→VXZ )
Y→X ( using decomposition inference rule on Y→VXZ )
Y→Z ( using decomposition inference rule on Y→VXZ )
(a) AE, BE
(b) AE, BE, DE
(c) AEH, BEH, BCH
(d) AEH, BEH, DEH
(a) CD
(b) EC
(c) AE
(d) AC
(a) AE, BE
(b) AE, BE, DE
(c) AEH, BEH, BCH
(d) AEH, BEH, DEH
A->B
A->C
CD->E
B->D
E->A
Which of the following functional dependencies is NOT implied by the above set?
(a) CD->AC
(b) BD->CD
(c) BC->CD
(d) AC->BC
(a)CF+ = {ACDEFG}
(b)BG+ = {ABCDG}
(c)AF+ = {ACDEFG}
(d)AB+ = {ABCDFG}
(a) {E,F}
(b) {E,F,H}
(c) {E,F,H,K,L}
(d) {E}
(A) 3
(B) 4
(C) 5
(D) 6
92
Copyright © 2021, ABES Engineering College