0% found this document useful (0 votes)
8 views65 pages

Unit-3 FD

The document discusses functional dependency in relational database design, emphasizing its importance in minimizing redundancy and data dependency among attributes. It covers the identification of functional dependencies, types of dependencies (trivial, non-trivial, transitive, multivalued), and introduces Armstrong's Axioms as foundational rules for understanding these dependencies. Additionally, it explains the concepts of full and partial functional dependencies with examples to illustrate their significance in database normalization.

Uploaded by

ishita15205
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views65 pages

Unit-3 FD

The document discusses functional dependency in relational database design, emphasizing its importance in minimizing redundancy and data dependency among attributes. It covers the identification of functional dependencies, types of dependencies (trivial, non-trivial, transitive, multivalued), and introduces Armstrong's Axioms as foundational rules for understanding these dependencies. Additionally, it explains the concepts of full and partial functional dependencies with examples to illustrate their significance in database normalization.

Uploaded by

ishita15205
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 65

Functional Dependency

(Unit 3)
Introduction – 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

2
Functional dependency in a relation (table)

• A functional dependency (FD) is a relationship that exists between


two attributes of a Relation (table).
• For any Relation R, attribute Y is said to be functionally dependent on
attribute X, if, for every valid instance of X, the value of X uniquely
determines the value of Y. This relationship is indicated by the
representation below:
X→Y
X can determine Y, means if t1.X = t2.X then t1.Y = t2.Y, where t1 and t2 are two tuples of the
Relation.
X & Y can be single attributes or a set of attributes
The left side of the above FD is called the determinant, and the right side is the dependent

3
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.

4
Functional Dependency- Example
Example
Assume we have an employee relation with attributes: EMPLOYEE Relation/Table
E-ID, E-NAME, E-CITY, E-STATE.
E-ID attribute can uniquely identify (determine) the E-NAME E-ID E-NAME E-CITY E-STATE
attribute of employee table because if we know the E-ID, we can E001 John Delhi Delhi
tell that employee name associated with it.
E002 Mary Delhi Delhi
Functional dependency can be written as:
E003 John Noida U.P.
E-ID → E-NAME
We can say that E-NAME is functionally dependent on E-ID.

Can we say?
E-NAME -> E-CITY
E-CITY -> E-STATE
Functional dependency in a relation (table)…
Example

• 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.
6
Types of functional dependencies
Functional dependencies can be classified into four types:

1. Trivial Functional Dependency


2. Non-trivial Functional Dependency
3. Transitive Functional Dependency
4. Multivalued Functional Dependency

7
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.

(dept_id, section_name) → (section_name) is a trivial functional dependency, since the


dependent section_name is a subset of determinant set (dept_id, section_name)
Similarly, dept_id → dept_id is also an example of trivial functional dependency

19
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
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.

The functional dependencies are:


roll_no → name, roll_no → gender, roll_no → city, roll_no → state, city → state
Here, roll_no → state is a transitive functional dependency because an attribute city exists, which is not a
Candidate Key, and roll_no → city & city → state hold.

21
Transitive Functional Dependency…
• Let’s assume a student relation as below.

The functional dependencies are:


roll_no → name, roll_no → adhaar_no, roll_no → gender, roll_no → city, roll_no → state, adhaar_no →
roll_no, adhaar_no → name, adhaar_no → gender, adhaar_no → city, adhaar_no → state, city → state
Is there a transitive dependency here between roll_no → name, as roll_no → adhaar_no & adhaar_no →
name holds true?
The answer is NO because the second determinant adhaar_no is the Candidate Key here.

Multivalued functional dependency
To understand a multivalued dependency, it is helpful to revisit what a functional dependency is.
• Functional dependencies rule out certain tuples from being in a Relation i.e. If A→B, we cannot have two
tuples with the same A value but different B values.
Suppose an attribute X uniquely determines an attribute Y. In that case, Y is functionally dependent on X.
This is written as X→Y. For example, in the STUDENT Relation below, the roll_no determines the name:

This functional dependency can be written: roll_no → name.


Each roll_no determines exactly one name and no more.
• In contrast to the functional dependency, the multivalued dependency requires that certain tuples be
present in a relation. Therefore, a multivalued dependency is a special case of tuple-generating dependency.
• Multivalued dependencies are a consequence of handling multivalued attributes as part of the normalization
process (discussed in detail in later units)
Multivalued Dependency Cont.…
Suppose we have following schema:
employee (emp_id, emp_name )
emp_info (emp_id, dependent, phone_num )

Here, emp_id → {dependent, phone_num} is a multivalued functional dependency, since the


dependents ’dependent’ & ’phone_num’ are not dependent on each other(i.e. dependent →
phone_num or phone_num → dependent doesn’t exist !). So, here we have a MVD emp_id->>dependent and
emp_id->>phone_num.
Formal Definition of MVD
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].

The EMP relation with two MVDs: ENAME —>> PNAME and
ENAME —>> DNAME.
Types of MVD
Multivalued dependency categorized into two types such as:
• Trivial Multivalued dependency
• Non-trivial Multivalued dependency
Trivial Multivalued dependency Cont.…
• Trivial Multivalued Dependency –An MVD A →→ B on R is trivial if B⊆A or A ∪ B = R (i.e. A ∪ B is all attributes of R).
• It occurs when we have one multivalued attribute in a relation
Let’s take an example of a student relation, where we have one multivalued attribute sport which
contains the name of sports played by a student. (a student can play multiple sports)

roll_no name sport


191306280 Aayushi Tennis, Basketball
As per the formal definition of a relation, an attributes can hold only atomic values, hence the above
relation is invalid 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.
Non-trivial Multivalued dependency
• Non-trivial Multivalued Dependency - occurs when there are more than one independent multivalued attribute
in a Relation.
If a student relation has two (or more) multivalued attributes, sports ( a student can play multiple sports) and
clubs ( a student can be a part of multiple clubs), and these two attributes are independent of each other, this
creates a non-trivial multivalued dependency in a relation.

roll_no name sport club


191306280 Aayushi Tennis, Basketball Dramatics, NSS
Converting the above into a valid relation to hold only atomic values.

roll_no name sport club


191306280 Aayushi Tennis Dramatics
191306280 Aayushi Basketball NSS
191306280 Aayushi Tennis NSS
As we have two multivalued independent attributes
191306280 AayushiinBasketball
the same relation,
we get into a problem of having to
Dramatics
repeat every value of one attribute with every value of another attribute to keep the relation state consistent
and to maintain the independence among the attributes involved.
In this case: roll_no →→ sport and roll_no →→ club
This is read as "roll_no multi-determines sport" and "roll_no multi-determines club".
Armstrong’s Axioms in Functional Dependency in DBMS

Armstrong's Axioms has two different set of rules,


1.Axioms or primary rules
1. Axiom of Reflexivity
2. Axiom of Augmentation
3. Axiom of Transitivity
2.Additional rules or Secondary rules
1. Union
2. Composition
3. Decomposition
4. Pseudo Transitivity
1. Axiom of Reflexivity:

If A is a set of attributes and B is a subset of A, then A holds B. { A → B }

Example:
X = {a, b, c, d, e}
Y = {a, b, c}
2. Axiom of Augmentation:

If A hold B and C is a set of attributes, then AC holds BC. {AC → BC}


i.e, if X→Y then XA→YA,
where A is set of attributes

Example:
For R(ABCD), if A → B then AC → BC
3. Axiom of Transitivity:

If A holds B and B holds C, then A holds C.


i.e, If {A → B} and {B → C}, then {A → C}

If A holds B {A → B} means that A functionally determines B.

Example:
if (X→Y & Y→Z) then X→Z
Secondary Rules - Union

If X determines Y and X determines Z, then X must also determine Y and Z.


i.e, If X → Y and X → Z then X → YZ

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)
2. Decomposition
If X determines Y and Z, then X determines Y and X determines Z separately.
i.e, If X → YZ then X → Y and X → Z

Proof:

1. X → YZ (given)
2. YZ → Y (using Reflexivity Rule)
3. X → Y (using Transitive Rule on 1 and 2) ……….(i)
4. X → YZ (given)
5. YZ → Z (using Reflexivity Rule)
6. X → Z (using Transitive Rule on 4 and 5) ………..(ii)
3. Composition
If P holds Q (P → Q) and A holds B (A → B), then PA → QB.

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)
4. Pseudo Transitivity
In Pseudo transitive Rule, if X determines Y and YZ determines W, then XZ determines W.

i.e, If X → Y and WY → Z then WX → Z

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)
Types of Functional Dependency
• Full Functional Dependency: In a functional dependency A→B (A is a set of attributes and B is another set of
attributes), the dependency where B is fully dependent on A and not on any of the subsets of A is called Full
Functional dependency.
For example, assume that attributes P and Q together can only uniquely identify the value of the other
attribute R. Then, PQ→R is Full Functional Dependency.

• Partial Functional Dependency: A functional dependency A→B (A is a set of attributes and B is another set
of attributes) is said to be partial if any subset of A can still recognize B uniquely.
For example, in a functional dependency PQ→R, if either P alone or Q alone can uniquely identify R, this is
said to be Partial Functional Dependency. We read this as R is partially functionally dependent on P or R is
partially functionally dependent on Q.

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.
Attribute
• Attribute closure of anClosure
attribute set can be defined as a set of attributes that can be
functionally determined from it.

• 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+.

• Steps to find the attribute closure of A (represented as A+)


Add A to A+
Recursively add attributes that can be functionally determined from attributes of the Relation
R.
Algorithm for Finding the Attribute
Closure
Steps to find the attribute closure of A (represented as A+)
• Add A to A+
• Recursively add attributes that can be functionally determined from attributes of the
Relation R.
Algorithm to compute a+, the closure of a under F
Result:= a; Here , a is attribute for which we are
while (changes to Result) do finding the closure
for each B → Y in F do F is the set of FDs
Begin
B->Y one FD in the F
if B ⊆ Result then Result := Result ∪ Y
End

28
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,E}
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}
Closure of a Set of Functional Dependencies

Algorithm to find the FD closure

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
30
Example for finding FD closure
• Given a Relation schema R=(A,B,C,G,H,I) and set of Functional
dependencies
F={A->B, A->C, CG->H, CG->I, B->H}
from F, it is possible to derive following dependencies.
A->H (By using transitivity A->B, B->H)
CG->HI ( By using union CG->H, CG->I)
AG->I (By using Pseudo transitivity rule implies that AG->I)
AG->CG ( By using Augmentation rule X->Y, XZ->YZ)
Etc.
31
Identifying Keys in a Relation by using
Attribute
Definition Closure
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.

Identifying Super Key and Candidate Key using attribute closure


• The set of attributes whose attribute closure is a set of all attributes of Relation is
called the Super Key of the Relation.
• The minimal set of attributes whose attribute closure is a set of all attributes of
Relation is called the Candidate Key of the Relation. This means that a Super Key
whose proper subset is not a Super Key is a Candidate Key.
Finding Super Keys of a relation using FD
sets and attribute closure
Definition - Any subset of attributes of a Relation that can uniquely identify all the tuples of that Relation is
known as a Super Key.
By the formal definition of a Relation, we know that all the tuples of a Relation should be unique. So the set of all
attributes itself is a Super Key.

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.

How many attribute combinations are possible?


Assume a Relation R (a1, a2, a3), the possible Super Keys are:- {a1,a2,a3}, {a1,a2}, {a2,a3}, {a1,a3}, {a1}, {a2}, {a3} = 7 nos.
The total number of possible Super Keys is given by the formula 2 n-1, Where n = Total number of attributes.

In the above Relation R(A, B, C, D, E), we will have 25-1 = 31 possible combinations, which can be Super Keys.
Finding Super Keys of a relation using FD
Now sets and attribute
after computing the closures closure…
of all the possible combination of attributes of
Relation R(A,B,C,D,E) with FD set F = {AB→C, B→E, C→D}, the following Super
Keys have been found:
1. {A,B,C,D,E}
2. {A,B,D,E}
3. {A,B,C,E}
4. {A,B,C,D}
5. {A,B,E}
6. {A,B,D}
7. {A,B,C}
8. {A,B}
Finding Candidate Keys of a relation using
called theFD sets andRelation.attribute closure…
As per the definition of Candidate Key - The minimal set of attributes whose attribute closure is a set of all attributes of Relation is
Candidate Key of the This means that a Super Key whose proper subset is not a Super Key is a Candidate
Key.
Now, if we look at the list of Super Keys, which we have found for Relation R(A,B,C,D,E), none of the Super Keys have a proper
subset which is not a Super Key except {A,B}.

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}
Prime attributes and non-prime attributes

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
Short Cut for finding candidate keys using
FD sets and attribute closure
Identifying Candidate Keys is very important for designing and implementing any database, as Candidate Keys help us to define
Primary Key and other keys which are essential for any database.
The process of identifying Candidate Keys illustrated above is very lengthy and time-consuming. We will now learn a more
practical and shorter way of identifying the Candidate Keys.

Steps for finding Candidate Keys


1. Determine all essential attributes of the given Relation.
• Essential attributes are those attributes that are not present on the right-hand side (RHS) of
any functional dependency.
• Essential attributes are always a part of every Candidate Key because they can not be
determined by other attributes.
2. Take a closure of essential attributes.
• If the closure of essential attributes returns all attributes of the Relation, essential
attributes become the Candidate Key and the only possible Candidate Key.
• If the closure of essential attributes does not return all attributes of the Relation
a) Take the whole Relation and start discarding the dependent attributes such that the remaining
attributes give a closure containing all attributes of the Relation.
Short Cut for finding candidate keys using
FD sets and attribute closure…
Steps for finding Candidate Keys (contd..)
b) The attributes remaining after discarding will be a Super Key as their closure is returning all attributes
of the Relation.
c) Now check if the proper subsets of this Super Key are Super Keys or not.
d) If the proper subsets are not the Super Key, then this Super Key becomes the Candidate Key.
• Check for more Candidate Keys by replacing already identified prime attributes (in the Candidate
Key) by their determinants if these prime attributes happen to be on the RHS for any FD.
• Repeat this process till all options are considered.
e) If the proper subset is a Super Key, we need to check if the proper subset of this proper subset is the
Super Key. We need to keep checking till we reach a proper subset which is not a Super Key. This
proper subset will be the Candidate Key.
• Check for more Candidate Keys by replacing already identified prime attributes (in the Candidate
Key) by their determinants if these prime attributes happen to be on the RHS for any FD.
• Repeat this process till all options are considered.
Short Cut for finding candidate keys using
Example 1
FD sets and attribute closure…
Let R(A,B,C,D,E,F) be a Relation schema with the following FDs: A→B, C→D, D→E
Here, the attributes which are not present on RHS of any functional dependency are A, C, and F.
So, essential attributes are- A, C, and F.
Let’s take the attribute closure of essential attributes:-
(ACF)+
= {A,C,F}
= {A,C,F,B} ( Using A→B )
= {A,C,F,B,D} ( Using C→D )
= {A,C,F,B,D,E} ( Using D→E )
We can see that the closure of essential attributes returns all attributes of the Relation.
So we can conclude that (ACF) is a Candidate Key. Also, in this case, since the essential attributes are sufficient to determine all
attributes of the Relation, this Relation will have only one Candidate Key, which is the combination of the essential attributes.
Short Cut for finding candidate keys using
Example 2
FD sets and attribute closure…
Let R(A,B,C,D,E,F) be a Relation schema with the following FDs: C→F, E→A, EC→D, A→B
Essential attributes – C and E
Let’s take attribute closure of essential attributes:-
(CE)+
= {C,E}
= {C,E,F} ( Using C→F )
= {A,C,E,F} ( Using E→A )
= {A,C,D,E,F} ( Using E,C→D )
= {A,B,C,D,E,F} ( Using A→B )
We can see that the closure of essential attributes returns all attributes of the Relation.
So we can conclude that (CE) is a Candidate Key and an only Candidate Key.
Short Cut for finding candidate keys using
FD sets and attribute closure…
Example 3
Let R(A,B,C,D,E) be a Relation schema with the following FDs: BC→ADE, D→B
The FDs can be re-written as below using Armstrong’s Axiom of decomposition:
BC→A, BC→D, BC→E, D→B
Essential attributes – C
Let us take attribute closure of essential attributes:-
(C)+ = {C}
We can see that the closure of essential attributes does not return all attributes of the Relation.
So, we can conclude that though (C) is an essential element of any Candidate Key; however, it is not a Candidate
Key.
Short Cut for finding candidate keys using
FD sets and attribute closure…
Example 3 (contd.)
Let us take the Relation R(A,B,C,D,E) and start discarding the dependent attributes.
(ABCDE)+ = {A,B,C,D,E}
(BC)+ = {A,B,C,D,E} – discarding A, D & E as they can be determined by B & C
So, (BC) is a Super Key – To check if it is a Candidate Key, its proper subsets should not be Super Keys.
(B) & (C) are proper subsets of (BC)
(B)+ = {B} -----so not a Super Key
(C)+ = {C} -----so not a Super Key
Therefore (BC) is a Candidate Key – B, C are prime attributes.
To check if there are any more Candidate Keys – Check if already identified prime attributes are on RHS and can be
replaced by its determinant.
From the FD set, we can replace B with D.
Check if (DC) is a Candidate Key as per the above process. We will find that (DC) is also a Candidate Key.

Therefore the given Relation has two Candidate Keys – (BC) & (DC)
Short Cut for finding candidate keys using
FD sets and attribute closure…
Example 4
Let R(A,B,C,D,E) be a Relation schema with the following FDs: AB→CD, D→A, BC→DE
The FDs can be re-written as below using Armstrong’s Axiom of decomposition:
AB→C, AB→D, D→A, BC→D, BC→E
Essential attributes – B
Let us take attribute closure of essential attributes:-
(B)+= {B}
So, we can see that the closure of essential attributes does not return all attributes of the Relation.
So, we can conclude that though {B} is an essential element of any Candidate Key, however, it is not a Candidate Key.
Short Cut for finding candidate keys using
FD sets and attribute closure…
Example 4 (contd.)
Let us take the Relation R(A,B,C,D,E) and start discarding the dependent attributes.
(ABCDE)+ = {A,B,C,D,E}
(ABE)+ = {A,B,C,D,E} – discarding C & D as they can be determined by A & B
So, (ABE) is a Super Key – To check if it is a Candidate Key, its proper subsets should not be Super Keys.
(AB) & (BE) are proper subsets of (ABE), not considering subset AE as B is an essential attribute
(AB)+ = {A,B,C,D,E} ----- is a Super Key, so (ABE) cannot be a Candidate Key
(BE)+ = {B,E} -----so not a Super Key
(AB) can be a Candidate Key if its proper subsets (A) & (B) are not Super Keys
(A)+ = {A} -----so not a Super Key
(B)+ = {B} -----so not a Super Key
Therefore, (AB) is a Candidate Key.
Short Cut for finding candidate keys using
Example 4 (contd.)
FD sets and attribute closure…
To check if there are any more Candidate Keys – Check if already identified prime attributes (A) & (B) are on RHS and
can be replaced by its determinant.
We can see that A can be replaced by D, so we need to check if (DB) is a Candidate Key as per the above process. We
will find that (DB) is also a Candidate Key.
To check if there are any more Candidate Keys – Check if already identified prime attributes (A), (B) & (D) are on RHS
and can be replaced by its determinant.
We can see that D can be replaced by BC, so we need to check if (CB) is a Candidate Key as per the above process.
We will find that (CB) is also a Candidate Key.
Therefore the given Relation has three Candidate Keys – (AB), (BC), (BD)
Short Cut for finding candidate keys using
FD sets and attribute closure…
Example 5
Let R (W,X,Y,Z) be a Relation schema with the following FDs: Z→W, Y→XZ, WX→Y
The FDs can be re-written as below using Armstrong’s Axiom of decomposition:
Z→W, Y→X, Y→Z, WX→Y
Essential attributes – NIL
Let us take the Relation R(W,X,Y,Z) and start discarding the dependent attributes.
(WXYZ)+ = {W,X,Y,Z}
(YZ)+ = {W,X,Y,Z} – discarding W & X as they can be determined by Y & Z respectively
So, (YZ) is a Super Key – To check if it is a Candidate Key, its proper subsets should not be Super Keys.
(Y) & (Z) are proper subsets of (YZ)
(Y)+ = {Y,X,Z,W} ----- is a Super Key, so (YZ) cannot be a Candidate Key
(Z)+ = {Z,W} -----so not a Super Key
(Y) is a Candidate Key as it is a minimal set with no proper subsets.
Short Cut for finding candidate keys using
FD sets and attribute closure…
Example 5 (contd.)
To check if there are any more Candidate Keys – Check if the already identified prime attribute (Y) is on RHS and can
be replaced by its determinant.
We can see that Y can be replaced by WX (WX→Y), so we need to check if (WX) is a Candidate Key as per the above
process. We will find that (WX) is also a Candidate Key.
To check if there are any more Candidate Keys – Check if already identified prime attributes (Y), (W) & (X) are on
RHS and can be replaced by its determinant. We can see that W can be replaced by Z (Z→W), so we need to check if
(ZX) is a Candidate Key as per the above process. We will find that (ZX) is also a Candidate Key.
To check if there are any more Candidate Keys – Check if already identified prime attributes (Y), (W), (X) & (Z) are on
RHS and can be replaced by its determinant.
We can see that X can be replaced by Y (Y→X), Z can be replaced by Y (Y→Z), so we need to check if (ZY), (WY), (YX)
are Candidate Keys as per the above process. As (ZY), (WY) & (YX) have (Y) as a proper subset, and we found that (Y)
is a Candidate Key (or a Super Key), so (ZY), (WY) & (YX) will not be Candidate Keys.
Therefore the given Relation has three Candidate Keys – (Y), (WX), (ZX)
Short Cut for finding candidate keys using
FD sets and attribute closure…
Example 6
Let R(A,B,C) be a Relation schema with the following FDs: A→B, B→A
Essential attributes – C
Let us take attribute closure of essential attributes:-
(C)+= {C}
So, we can see that the closure of essential attributes does not return all attributes of the Relation.
So, we can conclude that though {C} is an essential element of any Candidate Key; however, it is not a Candidate
Key.
Let us take the Relation R (ABC) and start discarding the dependent attributes.
(ABC)+ = {A,B,C}
(AC)+ = {A,C,B} – discarding B as it can be determined A
So, (AC) is a Super Key – To check if it is a Candidate Key, its proper subsets should not be Super Keys.
Short Cut for finding candidate keys using
FD sets and attribute closure…
Example 6 (contd.)
(A) & (C) are proper subsets of (AC)
(A)+ = {A,B} ----- so not a Super Key
(C)+ = {C} -----so not a Super Key
Therefore (AC) is a Candidate Key – B, C are prime attributes.
To check if there are any more Candidate Keys – Check if already identified prime attributes are on RHS and can be
replaced by its determinant.

From the FD set, we can replace A with B.


Check if (BC) is a Candidate Key as per the above process. We will find that (BC) is also a Candidate Key.

Therefore the given Relation has two Candidate Keys – (AC) & (BC)
Equivalence of Sets of Functional
Dependencies
If we have two sets of FDs, FD1 & FD2, for a given Relation R, we will discuss how to find the relationship between two FD sets.
1. If all FDs of FD1 can be derived from FDs present in FD2, we can say that FD2 ⊃ FD1.
2. If all FDs of FD2 can be derived from FDs present in FD1, we can say that FD1 ⊃ FD2.
3. If 1 and 2 both are true, FD1 ≡ FD2.
Equivalence of Sets of Functional
Dependencies…
How to determine whether FD1 covers FD2 –

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.
Equivalence of Sets of Functional
Example
Dependencies…
A Relation R(A,B,C,D,E) has the following two sets of FDs, find if they are equivalent:
FD1 = {A→C, AC→D, E→AD, E→H}
FD2 = {A→CD, E→AH}

Step 1 – Check if FD1 covers FD2.

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)
Equivalence of Sets of Functional
Dependencies…
Example (contd.)
Step 2 – Check if FD2 covers FD1.
Find closure of LHS all FDs in FD1, with respect to FDs in FD2, and see if the closure returns the attributes on RHS.
(A)+ = {A,C,D} – the closure includes (C), thus A→C holds in FD2 also.
(AC)+ = {A,C,D} – the closure includes (D), thus AC→holds in FD2 also.
(E)+ = {E,A,H,C,D} – the closure includes (A) & (D), thus E→AD holds in FD2 also.
(E)+ = {E,A,H,C,D} – the closure includes (H), thus E→H holds in FD2 also.
As we can see that all FDs of FD1 hold in FD2 also; thus, FD2 covers FD1 (FD2 ⊃ FD1)

As, FD1 covers FD2 (FD1 ⊃ FD2) & FD2 covers FD1 (FD2 ⊃ FD1), therefore FD1 is equivalent to FD2 (FD1 = FD2).
Canonical Cover or Minimal Set of Functional
We canDependency
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.
Canonical Cover or Minimal Set of Functional
ExampleDependency…
1:
Find the canonical cover of a relational schema R(A,B,C,D) with a set of FDs = {B→A, AD→BC, C→ABD}

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}
Canonical Cover or Minimal Set of Functional
ExampleDependency…
1 (contd.)
Condition 2
Calculating closure of all FD {B→A, AD→B, AD→C, C→A, C→B, C→D}
1. (B)+
a) Closure (B)+ = {B,A} using FD = {B→A, AD→B, AD→C, C→A, C→B, C→D}
b) Closure (B)+ = {B} using FD = {AD→B, AD→C, C→A, C→B, C→D}
From 1 a and 1 b, we found that both the Closure( by including B→A and excluding B→A ) are not equivalent;
hence FD B→A is important and cannot be removed from the set of FD.
Hence resultant FD = {B→A, AD→C, C→A, C→B, C→D}
2. (AD)+
a) Closure (AD)+ = {A,D,B,C} using FD = {B→A, AD→B, AD→C, C→A, C→B, C→D}
b) Closure (AD)+ = {A,D,C,B} using FD = {B→A, AD→C, C→A, C→B, C→D}
From 2 a and 2 b, we found that both the Closure (by including AD→B and excluding AD→B) are equivalent;
hence FD AD→B is not important and can be removed from the set of FD.
Hence resultant FD = {B→A, AD→C, C→A, C→B, C→D}
Canonical Cover or Minimal Set of Functional
Dependency…
Example 1 (contd.)
3. (AD)+
a) Closure (AD)+ = {A,D,C,B} using FD = {B→A, AD→C, C→A, C→B, C→D}
b) Closure (AD)+ = {A,D} using FD = {B→A, C→A, C→B, C→D}
From 3 a and 3 b, we found that both the Closure (by including AD→C and excluding AD→C ) are not
equivalent; hence FD AD→C is important and cannot be removed from the set of FD.
Hence resultant FD = {B→A, AD→C, C→A, C→B, C→D}
4. (C)+
a) Closure (C)+ = {C,A,B,D} using FD = {B→A, AD→C, C→A, C→B, C→D}
b) Closure (C)+ = {C,B,D,A} using FD = {B→A, AD→C, C→B, C→D}
From 4 a and 4 b, we found that both the Closure (by including C→A and excluding C→A) are equivalent; hence
FD C→A is not important and can be removed from the set of FD.
Hence resultant FD = {B→A, AD→C, C→B, C→D}
Canonical Cover or Minimal Set of Functional
Dependency…
Example 1 (contd.)
5. (C)+
a) Closure (C)+ = {C,B,D,A} using FD = {B→A, AD→C, C→B, C→D}
b) Closure (C)+ = {C,D} using FD = {B→A, AD→C, C→D}
From 5 a and 5 b, we found that both the closure (by including C→B and excluding C→B) are not equivalent;
hence FD C→B is important and cannot be removed from the set of FD.
Hence resultant FD = {B→A, AD→C, C→B, C→D}
6. (C)+
a) Closure (C)+ = {C,D,B,A} using FD = {B→A, AD→C, C→B, C→D}
b) Closure (C)+ = {C,B,A} using FD = {B→A, AD→C, C→B}
From 6 a and 6 b, we found that both the Closure( by including C→D and excluding C→D) are not equivalent,
hence FD C→D is important and cannot be removed from the set of FD.
Hence resultant FD = {B→A, AD→C, C→B, C→D}
Canonical Cover or Minimal Set of Functional
Dependency…
Example 1 (contd.)
Condition 3
Since FD = {B→A, AD→C, C→B, C→D} is resultant FD, now we have to check the redundancy of attributes on LHS;
since the left side of FD AD→C has two attributes, let us check their importance, i.e., whether they both are
important or only one.
(AD)+ = {A,D,C,B} using FD = {B→A, AD→C, C→B, C→D}
(A)+ = {A} using FD = {B→A, AD→C, C→B, C→D}
(D)+ = {D} using FD = {B→A, AD→C, 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}.
Canonical Cover or Minimal Set of Functional
ExampleDependency…
2:
Find canonical cover for a relational Schema R(V,W,X,Y,Z) and set of FDs = {V→W, VW→X, Y→VXZ}.

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 )

Now set of FD = {V→W, VW→X, Y→V, Y→X, Y→Z}


Canonical Cover or Minimal Set of Functional
Dependency…
Example 2 (contd.)
Condition 2
Calculating closure of all FD {V→W, VW→X, Y→V, Y→X, Y→Z}
1. (V)+
a) Closure (V)+ = {V,W,X} using FD = {V→W, VW→X, Y→V, Y→X, Y→Z}
b) Closure (V)+ = {V} using FD = {VW→X, Y→V, Y→X, Y→Z}
From 1 a and 1 b, we found that both the Closure( by including V→W and excluding V→W) are not equivalent;
hence FD V→W is important and cannot be removed from the set of FD.
Hence resultant FD = {V→W, VW→X, Y→V, Y→X, Y→Z}
2. (VW)+
a) Closure (VW)+ = {V,W,X} using FD = {V→W, VW→X, Y→V, Y→X, Y→Z}
b) Closure (VW)+ = {V,W} using FD = {V→W, Y→V, Y→X, Y→Z}
From 2 a and 2 b, we found that both the Closure( by including VW→X and excluding VW→X ) are not
equivalent, hence FD VW→X is important and cannot be removed from the set of FD.
Hence resultant FD = {V→W, VW→X, Y→V, Y→X, Y→Z}
Canonical Cover or Minimal Set of Functional
ExampleDependency…
2 (contd.)
3. (Y)+
a) Closure (Y)+ = {Y,V,X,Z,W} using FD = {V→W, VW→X, Y→V, Y→X, Y→Z}
b) Closure (Y)+ = {Y,X,Z} using FD = {V→W, VW→X, Y→X, Y→Z}
From 3 a and 3 b, we found that both the Closure( by including Y→V and excluding Y→V ) are not equivalent;
hence FD Y→V is important and cannot be removed from the set of FD.
Hence resultant FD = {V→W, VW→X, Y→V, Y→X, Y→Z}
4. (Y)+
a) Closure (Y)+ = {Y,X,V,Z,W} using FD = {V→W, VW→X, Y→V, Y→X, Y→Z}
b) Closure (Y)+ = {Y,V,Z,W,X} using FD = {V→W, VW→X, Y→V, Y→Z}
From 4 a and 4 b, we found that both the Closure( by including Y→X and excluding Y→X ) are equivalent; hence
FD Y→X is not important and can be removed from the set of FD.
Hence resultant FD = {V→W, VW→X, Y→V, Y→Z}
Canonical Cover or Minimal Set of Functional
ExampleDependency…
2 (contd.)
5. (Y)+
a) Closure (Y)+ = {Y,Z,V,W,X} using FD = {V→W, VW→X, Y→V, Y→Z}
b) Closure (Y)+ = {Y,V,W,X} using FD = {V→W, VW→X, Y→V}
From 5 a and 5 b, we found that both the Closure( by including Y→Z and excluding Y→Z ) are not
equivalent; hence FD Y→Z is important and cannot be removed from the set of FD.
Hence resultant FD = {V→W, VW→X, Y→V, Y→Z}
Canonical Cover or Minimal Set of Functional
Example 2 (contd.)
Dependency…
Condition 3
Since FD = {V→W, VW→X, Y→V, Y→Z} is resultant FD now, we have to check the redundancy of the attributes on
LHS; since the left side of FD VW→X has two attributes at its left, let us check their importance, i.e., whether they
both are important or only one.
(VW)+ = VWX using FD = {V→W, VW→X, Y→V, Y→Z}
(V)+ = VWX using FD = {V→W, VW→X, Y→V, Y→Z}
(W)+ = W using FD = {V→W, VW→X, Y→V, Y→Z}
Since the (VW)+, (V)+, (W)+, we found that all the Closures of VW and V are equivalent, hence in FD VW→X, W is not
at all an important attribute and can be removed.

Hence resultant FD = {V→W, V→X, Y→V, Y→Z} and we can rewrite as


FD = {V→WX, Y→VZ} is Canonical Cover of FD = {V→W, VW→X, Y→VXZ}
Thank You

65

You might also like