0% found this document useful (0 votes)
35 views66 pages

Functional Depencies

The document provides an overview of functional dependencies in relational databases, defining them as constraints between attribute sets that dictate how tuples relate to one another. It discusses the concept of closure for functional dependencies, inference rules for deriving new dependencies, and the significance of minimal sets of functional dependencies. Additionally, it covers normalization processes to minimize redundancy and anomalies in database relations, detailing first, second, and third normal forms.

Uploaded by

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

Functional Depencies

The document provides an overview of functional dependencies in relational databases, defining them as constraints between attribute sets that dictate how tuples relate to one another. It discusses the concept of closure for functional dependencies, inference rules for deriving new dependencies, and the significance of minimal sets of functional dependencies. Additionally, it covers normalization processes to minimize redundancy and anomalies in database relations, detailing first, second, and third normal forms.

Uploaded by

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

Functional Dependencies

Introduction
Formal tool for analysis of relational schemas

• A functional dependency is a constraint between two sets of attributes from the


database.

• Definition. A functional dependency, denoted by X → Y, between two sets of


attributes X and Y that are subsets of R specifies a constraint on the possible
tuples that can form a relation state r of R. The constraint is that, for any two
tuples t1 and t2 in r that have t1[X] = t2[X], they must also have t1[Y] = t2[Y].

• A functional dependency is a property of the semantics or meaning of the


attributes.
• Relation extensions r(R) that satisfy the functional dependency constraints are
called legal relation states (or legal extensions) of R
• Diagrammatic notation for displaying FDs: Each FD is displayed as a
horizontal line. The left-hand-side attributes of the FD are connected by
vertical lines to the line representing the FD, while the right-hand-side
attributes are connected by the lines with arrows pointing toward the
attributes.

Caption
Caption

Caption
F Closure - F +

• We denote by F the set of functional dependencies that are specified on


relation schema R.

• Typically, the schema designer specifies the functional dependencies that are
semantically obvious; usually, however, numerous other functional
dependencies hold in all legal relation instances among sets of attributes that
can be derived from and satisfy the dependencies in F. Those other
dependencies can be inferred or deduced from the FDs in F
• F = {Ssn -> {Ename, Bdate, Address, Dnumber}, Dnumber -> {Dname, Dmgr_ssn}}

Caption
• Ssn -> {Name, Dmgr_ssn}
• Ssn -> Ssn
• Dnumber -> Dnumber
• Definition. Formally, the set of all dependencies that include F as well as all
dependencies that can be inferred from F is called the closure of F; it is
denoted by F+.

• The closure F+ of F is the set of all functional dependencies that can be


inferred from F.
• Inference rules can be used to infer new dependencies from a given set of
dependencies.

• We use the notation F |=X -> Y to denote that the functional dependency X-
>Y is inferred from the set of functional dependencies F.
Inference rule IR1 through IR6

• IR1 (reflexive rule) : if X ⊇ Y, then X → Y.


• IR2 (augmentation rule) : {X → Y} |= XZ → YZ
• IR3 (transitive rule) : {X → Y, Y → Z} |= X → Z
• IR4 (decomposition, or projective rule) {X → YZ} |= X → Y
• IR5 (union, or additive, rule) : {X → Y, X → Z} |= X → YZ
• IR6 (pseudo-transitive rule) : {X → Y, WY → Z} |= WX → Y
Proof of IR1

• Suppose that X → Y and that two tuples t1, and t2 exist in some relation
instance r of R such that t1[X] = t2[X].

• Then t1[Y] = t2[Y] because X ⊇ Y; hence, X → Y must hold in r.


Proof of IR2 {X → Y} |= XZ → YZ (by Contradiction)
• Assume that X → Y holds in a relation instance r of R but that XZ → YZ does not
hold.
• Then there must exist two tuples t1, and t2 in r such that
• (1) t1[X] = t2[X],
• (2) t1[Y] = t2[Y]
• (3) t1[XZ] = t2[XZ],
• (4) t1[YZ] ≠ t2[YZ],
• This is not possible because from (1) and (3) we deduce
• (5) t1[Z] = t2[Z],
• and from (2) and (5) we deduce
• (6) t1[YZ] = t2[YZ], contradicting (4)
Proof of IR3 {X → Y, Y → Z} |= X → Z
• Assume that (1) X → Y and (2) Y → Z both hold in a relation r.
• Then for any two tuples t1 and t2 in r such that t1[X] = t2[X],
• we must have (3) t1[Y] = t2[Y],
• from assumption (1); hence, we must also have (4) t1[Z] = t2
[Z], from (3) and assumption (2); hence, X. → Z must hold in r
Proof of IR4 (Using IR1 through IR3).
{X → YZ} |= X → Y

1. X → YZ (given).

2. YZ → Y (using IR1 and knowing that YZ ⊇ Y).

3. X → Y (using IR3 on 1 and 2).


Proof of IR5 (Using IR1 through IR3).
{X → Y, X → Z} |= X → YZ

1. X → Y (given).

2. X → Z (given).

3. X → XY (using IR2 on 1 by augmenting with X; notice that XX = X).

4. XY → YZ (using IR2 on 2 by augmenting with Y).

5. X → YZ (using IR3 on 3 and 4)


Proof of IR6 (Using IR1 through IR3).
{X → Y, WY → Z} |= WX → Y

1. X →Y (given).

2. WY → Z (given).

3. WX → WY (using IR2 on 1 by augmenting with W).

4. WX → Z (using IR3 on 3 and 2)


Armstrong's inference rules

• Inference rules IR1 through IR3 are known as Armstrong's inference rules.
• It has been shown by Armstrong (1974) that inference rules IR1 through IR3 are
sound and complete.
• By sound, we mean that given a set of functional dependencies F specified on a
relation schema R, any dependency that we can infer from F using IR1 through
IR3 holds in every relation state r of R that satisfies the dependencies in F.
• By complete, we mean that using IR1 through IR3 repeatedly to infer
dependencies until no more dependencies can be inferred results in the
complete set of all possible dependencies that can be inferred from F.
X Closure (X+)

• Closure of an attribute X is the set of all attributes that are functional


dependencies on X with respect to F. It is denoted by X+ which
means what X can determine.
• For each set of attributes X that appears as a left-hand side of some
functional dependency in F, the set of all attributes that are dependent
on X is determined.
• Algorithm 10.1. Determining X+, the Closure of X under F
X+:= X;

repeat

oldX+ := X+;

for each functional dependency Y-> Z in F do


if X+ ⊇ then X+ := X+ U Z;

until (X+ = oldX+);


• Consider a relation R(A,B,C,D,E,F)
• F= {E->A, E->D, A->C, A->D, AE->F, AG->K}
• Find the closure of E or E+
• Let the relation R(A,B,C,D,E,F)
• F= {B->C, BC->AD, D->E, CF->B}
Find the closure of B.
Solution

The closure for B is as follows −

B+ = {B,C,A,D,E}
Equivalence of Sets of Functional Dependencies

• Definition: Two sets of functional dependencies E and F are equivalent if


E+= F+. Therefore, equivalence means that every FD in E can be inferred from
F, and every FD in F can be inferred from E; That is, E is equivalent to F if
both the conditions E covers F and F covers E hold.
• Definition. A set of functional dependencies F is said to cover another set of
functional dependencies E if every FD in E is also in F+; that is, if every
dependency in E can be inferred from F; alternatively, we can say that E is
covered by F.
• We can determine whether F covers E by calculating X + with
respect to F for each FD X-> Y in E, and then checking
whether this X+ includes the attributes in Y. If this is the case
for every FD in E, then F covers E.
• We determine whether E and F are equivalent by checking
that E covers F and F covers E.
Example

• R(ABC)
• F={A->B, B->C, C->A}
• G={C->B, B->A, A->C}
• Given below are two sets of FDs for a relation R(A,B,C,D,E). Are they
equivalent?

1. A->B, AB->C,D->AC, D->E


2. A->BC, D->AE
Minimal Sets of Functional Dependencies
• A minimal cover of a set of functional dependencies E is a set
of functional dependencies F that satisfies the property that
every dependency in E is in the closure F+ of F.
Example-1

• R(ABC)
• F={A->B, AB->C}
• A+ = {ABC}
• Since A+ is {ABC} we can simplify functional dependency F as
E={A->B, B->C}
• Informally, a minimal cover of a set of functional
dependencies E is a set of functional dependencies F
that satisfies the property that every dependency in E is
in the closure F+ of F.
Example-2

• R(ABC)
• F={A->B, B->C, A->C}
• A+ = {ABC}
• B+ = {BC}
• Minimal FD
• E={A->B, B->C}
A functional dependency F is said to be minimal if it satisfies the
following conditions:
1. Every dependency in F has a single attribute for its right-hand side.
2. We cannot replace any dependency X->A in F with a dependency Y->A,
where Y is a proper subset of X, and still have a set of dependencies that
is a equivalent to F.
3. We cannot remove any dependency from F and still have a set of
dependencies that is equivalent to F.
• Simplified definition
1. Single attribute on the RHS of the FD.
2. No extraneous LHS attribute. (Example-1)
3. No redundant FDs. (Example-2)
Minimal Cover - Example
• R(ABCDE)
• F={A->D, BC->AD, C->B, E->A, E->D}
• Step-1
• F={A->D, BC->A, BC->D, C->B, E->A, E->D}
• Step-2
• For FD BC->A [B+= B, C+=CBAD] – Eliminate B from LHS
• F={A->D, C->A, BC->D, C->B, E->A, E->D}
• For FD BC->D [B+= B, C+=CBAD]
• F={A->D, C->A, C->D, C->B, E->A, E->D}
• Step-3
• F={A->D, C->A, C->B, E->A}
Exercises
1. Given FD E={B->A,D->A, AB->D}. Find the minimum cover.
2. Is the set of functional depencies G= {Ssn-> {Ename, Bdate,
Address, Dumber}, Dnumber -> {Dname, Dmgr_ssn}} minimal? fI
not, try to find a minimal set of functional dependencies that is
equivalent to G. Prove that your set is equivalent to G.
3. A set fo FDs for the relation R(A, B, C, D, E, F) is AB->C, C-> A, BC
-> D, ACD->B, BE->C, EC->FA, CF -> BD, D->E. Find a minimum
cover for this set of FDs.
Using FDs to determine Keys

• Prime attributes
• An attribute is a prime attribute if it is part of any key.
• Non-Prime attributes
• An attribute is a non-prime attribute if it is not part of any key.
Example

1. R(ABC)
• F={A->B, B->C} – ANS: Key A, PRIME – A and Non-Prime - BC
2. R(ABCD)
• F={AB->C, C->B, C->D} – ANS: Key AB, AC
Prime – ABC, Non-prime - D

3. R(ABC)
• F={A->B, B->C, C->A} – ANS: Key A, B, C
Prime – ABC, Non-prime - NIL
Normalization of Relations

• The normalization process, as first proposed by Codd (1972a), is a process of


analyzing the given relation schemas based on their FDs and primary keys to
achieve the desirable properties of (1) minimizing redundancy and (2)
minimizing the insertion, deletion, and update anomalies
• Initially, Codd proposed three normal forms, which he called first, second,
and third normal form. A stronger definition of 3NF—called Boyce-Codd
normal form (BCNF)—was proposed later by Boyce and Codd.
First Normal Form
• The only attribute values permitted by 1NF are single atomic (or indivisible)
values.
• There are three main techniques to achieve first normal form for such a relation:
• Remove the attribute Dlocations that violates 1NF and place it in a separate
relation DEPT_LOCATIONS along with the primary key Dnumber of
DEPARTMENT. This decomposes the non-1NF relation into two 1NF relations.
• Expand the key, as shown in Figure 15.9(c). In this case, the primary key becomes
the combination {Dnumber, Dlocation}. This solution has the disadvantage of
introducing redundancy in the relation.
• If a maximum number of values is known for the attribute—for example, if it is
known that at most three locations can exist for a department—replace the
Dlocations attribute by three atomic attributes: Dlocation1, Dlocation2, and
Dlocation3. This solution has the disadvantage of introducing NULL values if most
departments have fewer than three locations.
Second Normal Form

• Second normal form (2NF) is based on the concept of full functional dependency.
A functional dependency X → Y is a full functional dependency if removal of any
attribute A from X means that the dependency does not hold any more.
• A functional dependency X → Y is a partial dependency if some attribute A ε X can
be removed from X and the dependency still holds;

• Definition. A relation schema R is in 2NF if every nonprime attribute A in R


is fully functionally dependent on the primary key of R.
• General Definition. A relation schema R is in second normal form (2NF) if
every non- prime attribute A in R is not partially dependent on any key of
R.
Points to be noted

• A relation is in 2NF if and only if:


1. A relation is in 1NF.
2. No partial dependency of a Non-prime attribute on any keys or candidate
key.
Third Normal Form
• Third normal form (3NF) is based on the concept of transitive dependency.
A functional dependency X → Y in a relation schema R is a transitive
dependency if there exists a set of attributes Z in R that is neither a
candidate key nor a subset of any key of R, and both X → Z and Z → Y
hold.

• The dependency Ssn → Dmgr_ssn is transitive through Dnumber in


EMP_DEPT in Figure 15.3(a), because both the dependencies Ssn →
Dnumber and Dnumber → Dmgr_ssn hold and Dnumber is neither a key
itself nor a subset of the key of EMP_DEPT.
• Definition. According to Codd’s original definition, a relation
schema R is in 3NF if it satisfies 2NF and no nonprime
attribute of R is transitively dependent on the primary key.

• General Definition. A relation schema R is in third normal


form (3NF) if, whenever a nontrivial functional dependency X
→ A holds in R, either (a) X is a superkey of R, or (b) A is a
prime attribute of R.
• A relation is in 3NF if and only if:
1. The relation is in 2NF
2. For every FDs X->A, where A is a Non-prime X(LHS) has to be a SK.
OR
A(RHS) is a prime attribute.

• 3NF is violated if there exists a functional dependency (FD) X -> A, where


both X and A are non-prime attributes.
• Intuitively, we can see that any functional
dependency in which the left-hand side is part (a
proper subset) of the primary key, or any
functional dependency in which the left-hand
side is a nonkey attribute, is a problematic FD.
Suppose that there are two candidate keys: Property_id# and {County_name, Lot#}

2NF decomposition
3NF decomposition
Points to be noted

1. If all the keys are singleton attributes, then the relation


is in at least 2NF
2. If all the attributes are Prime attribute then the relation
is in 2NF and 3NF.
Boyce Codd Normal Form(BCNF)

• A relation is in BCNF if and only if:


1. It is in 3NF
2. For each non-trivial FD X->A, X must be a superkey [SK]
Example:

R(ABCDE). F={AB->CDE, D->A}. Candidate Key: AB, BD. Prime: A,B,D


This relation is in 3NF, but not in BCNF because of FD D->A
Example

• R(ABC)
• F={AB->C, C->A} Key – AB, BC, Prime=A,B,C
This relation is in 3NF but not in BCNF because of FD C->A, [C is not a SK]
Prove that any relation schema with two attributes is in BCNF
• Consider a relation schema R=(A, B) with two attributes. The only possible (non-
trivial) FDs are {A} ->{B} and {B} ->{A}. There are four possible cases:

1. No FD holds in R. In this case, the key is {A, B} and the relation satisfies BCNF.
2. Only {A} ->{B} holds. In this case, the key is {A} and the relation satisfies BCNF.
3. Only {B} ->{A} holds. In this case, the key is {B} and the relation satisfies BCNF.
4. Both {A} ->{B} and {B} ->{A} hold. In this case, there are two keys {A} and {B} and
the relation satisfies BCNF.

Hence, any relation with two attributes is in BCNF.


Dependency preservation and Lossless join

• Two important properties of decomposition:


1. Lossless join
2. Dependency preservation
Dependency preserving
• When decomposing a relation R with functional dependencies (FDs) F into
R1, R2, ..., Rn, the union of the FDs in R1, R2, ..., Rn, denoted as G, must be
equivalent to the original set of FDs, F.

• R(ABCDE)- F={A->B, B->C,C->D, D->A}


• R1(ABC), R2(CDE)
• FDs of R1 are F1={A->BC, B->CA, C->AB}
• FDs of R2 are F2={C->D, D->C}
• G= F1 U F2, G={A->BC, B->CA, C->AB, C->D, D->C}
• G and F are equivalent.
Lossless join

• Lossless join decomposition is a decomposition of a relation R into relations


R1, R2 such that if we perform a natural join of relation R1 and R2, it will
return the original relation R. A B C
a1 b1 c1
• Example – A2 b1 c1

• R(ABC) – F={A->B, B->C}. Key-A a3 b2 c2

• R1(AB) R2(BC) A B B C
a1 b1 b1 c1
a2 b1
b2 c2
a3 b2
Exercises
1. R(ABCD). F={AB->CD, C->A, D->B}
All attribute are prime attribute. Therefore, this relation is in 2NF as well as
3NF.

2. R(ABCD). F={A->B, B->C, C->D}


KEY- A.
**This relation is in 2NF.
**KEY is a single attribute. Therefore, no partial dependency on the key.
**But this relation violates 3NF due to the functional dependencies B->C and
C->D
3. R(ABCDEF). F={AB->CDEF, BD->F}
KEY - AB
**This relation is in 2NF but not in 3NF. Functional dependency BD->F
violates 3NF.
Identify the highest Normal Form
1. R(ABCDEFGH). F={ABC->DE, E->GH, H->G, G->H, ABCD->EF}
KEY – ABC PRIME- ABC NON-PRIME- DEFGH
**FD1=ABC->DE, FD2=E->GH, FD3=H->G, FD4=G->H, FD5=ABCD->EF.
Not in BCNF. FD2, FD3, FD4 violates BCNF.
**FD2, FD3, FD4 ALSO violates 3NF. Therefore, not in 3NF.
Relation in 2NF as no partial dependency exist. (Highest NF is 2NF)
2. R(ABCD) F={AB->CD, AC->BD, BC->D} CANDIDATE KEY: AB, AC
AB->CD AC->BD BC->D
BCNF Y Y N
3NF Y Y N
2NF Y Y N

Highest NF is 1NF
3. R(ABCDE). F={AB->CDE, D->BE}. CANDIDATE KEY: AB, AD

AB->CDE D->BE
BCNF Y N
3NF Y N
2NF Y N
4. R(ABCDE) F={A->BCDE, BC->ACE, D->E}
CANDIDATE KEY- A, BC. Prime – ABC, Non-Prime-DE

A->BCDE BC->ACE D->E


BCNF Y Y N
3NF Y Y N
2NF Y Y Y
2NF IS THE HIGHEST NORMAL FORM.
• Consider the universal relation R = {A, B, C, D, E, F, G, H, I} and the set of
functional dependencies F = { {A, B} -> {C}, {A} -> {D, E}, {B} -> {F}, {F} ->{G,
H}, {D} -> {I, J} }. What is the key for R? Decompose R into 2NF, then 3NF
relations.
• Key – AB. Prime-AB, Non-Prime-CDEFGHI
• R1 = {A, D, E, I, J}, R2 = {B, F, G, H}, R3 = {A, B, C} – in 2NF
• R11 = {D, I, J}, R12 = {A, D, E}, R21 = {F, G, H}, R22 = {B, F}
• The final set of relations in 3NF are {R11, R12, R21, R22, R3}
Convert the relation to 2NF and 3NF

1. R(ABCD) F={A->B, B->C} KEY-AD, Prime: AD, Non=prime: BC


R1(ABC), R2(AD)

Relation R1, R2 are in 2NF.

R11(AB), R12(BC),
Relation R11, R12, R2 are in 3NF
Convert the relation to 2NF and 3NF

• R(ABCD) F={A->B, C->D}


KEY- AC , Prime: AC, Non-prime: BD

R1(AB) R2(CD) R3(AC)

Relation R1,R2,R3 are in 3NF


• Consider the universal relation R = {A, B, C, D, E, F, G, H, I} and the set of
functional dependencies G = { {A, B} -> {C}, {B, D} -> {E, F}, {A, D} -> {G, H},
{A} -> {I}, {H} -> {J} }. What is the key for R? Decompose R into 2NF, then 3NF
relations.
• Key - {A, B, D}
• R1 = {A, B, C, I}, R2 = {B, D, E, F}, R3 = {A, D, G, H, J}, R4 = {A, B, D}
• R11={A, I}, R12={A,B,C}.
• 2NF – R11, R12, R2, R3, R4
• R31 = {H, J}, R32 = {A, D, G, H}
• The final set of 3NF relations is {R11, R12, R2, R31, R32, R4}
• Consider a relation R(A,B,C,D,E) with the following dependencies: AB -> C,
CD -> E, DE -> B

• Is AB a candidate key of this relation? If not, is ABD? Explain your answer.


• No, AB+ = {A,B,C},a proper subset of {A,B,C,D,E} Yes, ABD+ = {A,B,C,D,E}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy