Example: Functional Dependencies (FD) Lets consider the following relation STUDENT(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).
Derived Functional Dependencies: Similarly: also
Example: Consider the following relations:
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:
The following rules can be derived from the previous three.
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
Proof of F5: Proof: (1) A BC given (2) BC B from F1 (3) BC C from F1 Therefore from F3: (4) A B and A C
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+ = X repeat old_x+ = X+ for each FD Y Z in F do if Y X+ then X+ = X+ Z until (old_x+ = X+)
Example: FD s: Using the above algorithm:
Example: Let R be a relation with attributes W, X, Y, Z and the functional dependencies: W Z YZ X WZ Y Q: Find the transitive closures W+, YZ+, WZ+. Which one is a key?
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 FDs if A result, then result = result B end_while 3. If Y is a subset of result, then FD X Y is redundant.
Example: Let R be a relation with attributes W, X, Y, Z and the functional dependencies: W Z W Y YZ X WZ Y Q: Find all redundant functional dependencies.
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.
Derivation Trees Definition: 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:
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+
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 Dependencies 1. 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.
NORMAL FORMS First Normal Form Definition: A relation is in first normal form if and only if every attribute is single-valued for each tuple. - No composite attributes. - No multivalue attributes.
Example:
NORMAL FORMS Second Normal Form Definition: A relation is in second normal form (2NF) if and only if it is in 1NF and all nonkey attributes are fully dependent on the key. Clearly if the relation is in 1NF and the key consists of a single attribute the relation is automatically 2NF.
Example: