functional dependencies (fd) - university of cyprusepl242/lectures/normalization_theory_2.pdf ·...
TRANSCRIPT
![Page 1: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/1.jpg)
Functional Dependencies (FD)Example:Lets consider the following relationSTUDENT(STUID, STUNAME, MAJOR, CREDITS, STATUS, SSN)
Constrains:• Each student has a unique SSN and ID.• Each student has at most one major.• Names are not unique.• CREDITS means the number of credits completed.• STATUS refer to the year the student is in (FSJS).
![Page 2: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/2.jpg)
• Derived Functional Dependencies:
• Similarly:
also
![Page 3: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/3.jpg)
Example:Consider the following relations:
![Page 4: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/4.jpg)
INFERENCE RULES for Functional Dependencies
• Called “inference Axioms” or Amstrong Axioms• Used to find all the FDs logically by a set of FDs.• Let A,B,C,D be subset of attributes of a relation R.• The following axioms hold:
![Page 5: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/5.jpg)
The following rules can be derived from the previous
three.
![Page 6: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/6.jpg)
Proof of F3:
Proof:Let assume that (1) A B and (2) B C holds. Then for two tuples t1, t2 such that t1[A] = t2[A] then (3) t1[B] = t2[B] and from (2) we must also have t1[C] = t2[C].
Hence A C
![Page 7: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/7.jpg)
Proof of F5:
Proof:(1) A BC given(2) BC B from F1(3) BC C from F1Therefore from F3:(4) A B and
A C
![Page 8: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/8.jpg)
• Definition:– Closure of a Functional Dependency Set F, F+:
If F is a set of functional dependencies for a relation R, the set of functional dependencies that can be derived from F, F+, is called the CLOSURE of F.
• Amstron’s axiom are sufficient to compute all of F+.Given a functional dependency g we want to determine whether it belongs into the given set of FD’s F (F+).
– Closure of an attribute X under F, X+.The set of all attributes that are functionally dependent on X under F.
Algorithm:X+ = Xrepeat
old_X+ = X+ for each FD Y Z in F do
if Y ⊆ X+ then X+ = X+ ∪ Z until (old_X+ = X+)
![Page 9: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/9.jpg)
Example:
FD’s:
Using the above algorithm:
![Page 10: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/10.jpg)
Example:Let R be a relation with attributes W, X, Y, Z and the functional dependencies:
W ZYZ XWZ Y
Q: Find the transitive closures W+, YZ+, WZ+.
Which one is a key?
![Page 11: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/11.jpg)
Discussion:• Given a set of functional dependencies we want to be able to
decide whether any of them is redundant.• Given a functional dependency g we want to determine
whether it belong into the given set of FD’s F (F+).• To decide redundancy we use the following algorithm:
1. Choose a candidate FD, say X Y, and remove it from the set of FDs.
2. result := X;while (result change and Y is not contained in) do
for each FD, A B, remaining in the reduced set of FDsif A ⊆ result, then result = result ∪ B
end_while3. If Y is a subset of result, then FD X Y is redundant.
![Page 12: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/12.jpg)
Example:
Let R be a relation with attributes W, X, Y, Z and the functional dependencies:
W ZW YYZ XWZ Y
Q: Find all redundant functional dependencies.
![Page 13: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/13.jpg)
Derivation Trees• Given a functional dependency g we want to
determine whether it belongs into the given set of FD’s F (F+).- Use the previous algorithm
or use
- Derivation Tree (DT). A tree representation of the previous algorithm with path information.
![Page 14: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/14.jpg)
Derivation TreesDefinition:Let F set of FD’s. The set of F-based derivation trees
(FBDT) is:1. If A is an attribute a node labeled with A is a FBDT.2. If T is FBDT with leaf node labeled A and
B1,B2,B3,…,Bn A ε F then the tree constructed from T by adding B1,B2,B3,…,Bn as children of the leaf node A is also a FBDT.
3. Nothing else.
Example:
![Page 15: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/15.jpg)
![Page 16: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/16.jpg)
• Let T be a FBTD, let Y be a nonempty set of labels of nodes of T, let X be the set of all attributes that appear as leaves of T.
THEN X Y ε F+• For given FD g : X Y and a set F of FD’s, g ε F+ if
there exist a F-based Derivation Tree (FBTD) rooted at Y.
Example:Let
Show if f : AB F ε F+
![Page 17: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/17.jpg)
Definitions:
• Equivalence of set of Functional Dependencies– A set of FDs E is set to be covered by a set of functional
dependencies F, if every FD in E is also in F+• F cover E
– Two sets of functional dependencies E and F are set to be equivalent if:E+ = F+
– Minimal set of Functional Dependencies1. Every dependency if F has a single attribute for its right-hand
side.2. We cannot remove any dependency from F and still have set of
dependencies equivalent to F.3. No attribute on the left hand side is redundant.
![Page 18: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/18.jpg)
NORMAL FORMS
• First Normal FormDefinition:A relation is in first normal form if and only if everyattribute is single-valued for each tuple.
- No composite attributes.- No multivalue attributes.
![Page 19: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/19.jpg)
Example:
![Page 20: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/20.jpg)
NORMAL FORMS
• Second Normal FormDefinition:A relation is in second normal form (2NF) if and only ifit is in 1NF and all nonkey attributes are fully dependenton the key.
Clearly if the relation is in 1NF and the key consists of a single attribute the relation is automatically 2NF.
![Page 21: Functional Dependencies (FD) - University of Cyprusepl242/lectures/Normalization_Theory_2.pdf · Discussion: • Given a set of functional dependencies we want to be able to decide](https://reader031.vdocuments.pub/reader031/viewer/2022021514/5b14bd5d7f8b9a7d068b8c77/html5/thumbnails/21.jpg)
Example: