You are on page 1of 10
Functional Dependencies & Normalization(2) RDB design goal: Generating a set of relation schemas that allow us to store information without un-necessary redundancy, yet easily retrievable. Normalization: ‘Schema refinement process to assure that the relation of DB conforms to the normal forms: 1 NF, 2 NF, 3 NF, BCNF, 4 NF and 5 NF. This is accomplished through review and examination of functional dependency(les). A.NF, unlike other normal forms, does not require information on fundamental dependencies. A relation schema R is in INF (first normal form) if the domain of all attributes of R are atomic, An integer attribute is atomic, where as a set of integers representing an attribute, is not atomic. Composite attributes such as an address attribute (street, city, state, zip) are non- atomic. Question: 1) How does oracle support non-atomic attributes? -> By creating types (ORDB) 2) Is anid attribute such as “HA4680” atomic? -> Yes, 3) Is ‘HA-Dept & 4680-Emp atomic? Needs extra programming, to break it down to atomics. Functional Dependencies: These are constraints on the set of DB relations that allow us to express facts about the enterprise we are modeling with our DB. Super key notion: Given: R: a relation schema K: a sub set of R (K < R) => Super key 1(R): relation “r* with R schema tt & t2: a pair of tuples in relation r. rere @ Dr Assadipour Page 1 no two tuples in relation r(R) may have the same value on attribute set K i.e., ; tr#te (two distinct tuples) 1 tik] # tlk] The notion of functional dependency generalizes the notion of super key. fe BcR and ti{al=teo} Given : Then the functional dependency: a> 8 (adetermines p) Functional dependencie are used in two ways: 1. Test relations to see whether they are under a given set of FD’s 2. To specify constraints on the set of legal relations [ holds on R). Set of FD's Schema Example: List all functional dependencies satisfied by the following relation A_ B Ic D ta at bt [et dt a 12 ai b2. ct a2 - a2 b2 2. a2 . a2 b2 02, a3 4 a3 b3. 2 4 *A > Cissatisfied =) t{A]= tiA] & tIC]=t{C] > Two tuples have an A value of a1 and C value c1. > Similarly two tuples have A value a2 and C value c2. > There are no other pairs of distinct tuples that have the same a value. @ Dr Assadipour Page 2 “C + Ais not satisfied. ty = (a2, b2, 02, d3) te = (a3, b3, c2, d4) > These two tuples have the same C values but different A values. > ‘Thus we have two tuples t; & tg such that: *AB — Dis satisfied. {AB} + D. & There is no pair of distinct ty & tz such that: tr [AB] = t [AB] > Therefore, if t; [AB] = te [AB], it must be: tet (identical tuples) > tM [D]= 21D] rsatisfies AB > D Interference Rules for Functional Dependencies: & Schema designer specifies the FD’s semantically obvious. > There may exist numerous other FD's. Other FD’s: can be inferred or deduced from FD's in F. Set of all such dependencies is called closure of F (F*). 7 v Example: IR 4; Reflexive rule: if Yc X then X > Y Inference Rules: IR 2: Augmentation: ifX -» Y then XZ -» YZ IR 3: Transitive rule: IfX >» Y&Y-> ZthenX > Z Armstrong's Rules Algorithm to determine closure of a set of ED Xt=X Repeat for each functional dependency X in X* [ apply reflexivity & augmentation in rules on X add the resultir g FD's to X* @ Dr Assacipour Page 3 for each pair of FD's X; & Xo in X* if X: & Xp can be combined thru transitivity E add the resulting FD to X* Closure set Theorem/Algorithm to find a* | The closure of “a‘under “F’, is defined the set of all attributes functionally determined by “a “under a set “F” of FD's. Result:= a; While (changes to result) do foreach FD B > yinF do begin if Bc result then result : = result Uy; end Example: Given the schema: R= (A,B,C, G,H, |) and the FD's. {A> B.A» CCG +H,CG+ 1,B +H} Find (AG)* Answer: First time execution of While” Result= AG ABG A> B caused inclusion of B in result. [ (A> BisinF and A < AG; result: = result UB). A> C causes the result to become ABCG CG +H causes the result to become ABCGH CG + I causes the result to become ABCGHI Second time execution of while add no new attribute. peter tn ttn taconite @ Dr Assadipour Page 4 Applications: 1) To test if ais a candidate key: a* must contain R attributes 2) To check if FD a B holds by B c a* Example: Ghven elation schema: | R (A,B, C, D, E) and the FD's {AB+ C,CD-> E,DE+ B} a. Is AB a candidate key? Answer: Find (AB)" and see if it contains all attributes in R. NO * Because of AB -> C, add C to the set ABC * The 2” and 3" FD’s add no new attributes to the resulting set. =) (AB)' = {A,B,C}, aproper subset of R. b. Is ABD a candidate key? + Because of AB -» C, result becomes: ABCD * Because of CD -> E, result becomes: ABCDE * The last FD, DE -» B, adds no new attribute. |) ABD)" = {A, B,C, D, E} As this set contains all attributes in R. ABD is a candidate key. Problem: (14-28) ~ Pg. 499 Tuple # A B c 1 10 bi 1 2 10 be Cs 3 11 be cy 4 12 bs Ca 5 13 bi ci 6 14 [bs [ee @ Dr Assadipour Page S A> B cannot hold Tuples # 1 & #3 agree on A- values but not on B-values. I) B+» Cmay hold Ill) C+ Bcannot hold tuples # 1 & #3 violate C+ B tuples # 3 & #5 violate C-> B Vv) B Acannot hold tuples #1  violate Be A tuples # 4 & #6 violate B-> A V) C+ Acannot hold tuples # 1 & #3 violateC > A B. Is AB a candidate key? Start with AB and fine (AB)" Using B > CandB < (AB) > (AB)* = {A, B, C} Is AC a candidate key? Can show (AC)' = {A, B, C} Is BC a candidate key? (BC)" = {B, C}—> doesn't contain all the attributes, so BC is not a candidate key. Summary: 1. Use closure set theorem to find the candidate keys. 2. Use a candidate key as PK and determines functional dependencies. 3. Decompose & normalize the DB. @ Dr Assadipour Page 6 Exercise: Given the customer — property relation (R): Gust No | Property_No | CName | P_Address [Rent_Start [Ranl Finish | Rent | Owner.No [O_Name ‘R76 PG4 John Kay 220, Main St | 1-Jul-01 31-aug-01 $850 | Coa0 Tina Murphy: R76 PGi6 John Kay 423, New St_| 1-Sep-01 41-Sep-02 $975 | CO03 Tony Shaw CREE PG4 Al Stewart [220,Main St | 41-Sep-89 [10-Jun-01 [$750 [C040 | Tine Murphy R56 PG36 | Al Stewart | 99, Center St | 10-Oct-00 01-Dec-01 $1500 | Coes ‘Tony Shaw ‘CREE PGI6 | AL Stewart | 123, New 4A-Nov-02, 40-Nov-03 | $1200 [Coes Tony Shaw Ave fee partial z A B c E F oc ok 1 Cifst_No | Property_No | CNart P_Address RenifSiar’ | Rert_Finish | Renf | Owher.No | O_Neme CRITE PGS ‘John 220, Main St | T-JuOt 3t-dug-01 | $8 CoO Tina Wiorohy CRE PCTS John Hay | 723, New St | 1-Seg-07 | 1-Stp-02 [$076 | Coos Tony Bhaw | eRe | PGE [Ab Start [220, Main St_ | 4-Sep-99 [70-Jun-01 | $75) | CO4O Tine urohy CREE PG36 [AL Stewart | 99, Center St | 10-08-00 | Ot-tpec-01 | $ tepo | cova Tony Bhaw HSS | PGI Al Stewart | 123, New Ave | -No}-02 _[TOov-03 | $1200 | cops ——_| Toi Bhaw + partial + transit a, Use R = {A, B, C, D, E, F, G, H, I} and list all functional dependencies. Determine the primary key for the relation using the Closure Set theory. fd: B> D,H fda:H > 1 fds AB+C,E,F,G (AaB) =? fd: B+ DLH& BcAB (AB)" = fA, B, D, H} fda: H > H ¢ {A,B, D, H} (A, B, D, H, |} (AB) fds: (AB)* contains all attributes in R. A, CEF,G &Ac{AB,D,H,!} (AB)" = A,B, C,D,E,F,H,1} ren ett ssn ranean @ Dr Assadipour Page 7 b. Construct a functional dependency diagram and label all dependencies c. Using the above FD diagram, normalize the relation to comply with 3 NF, Show the resulting Customer Owner rl c# C_Name Property- Rent B D HG >| Property # [P_Add [O# | Rent | Rental 3NF & BCNF —[c# |P# Rent. S | Rent. E As you write FD’s, itis very easy to write redundant ones. In the following example, you learn how to eliminate such redundancies. Example: Identifying redundant FD's: Given the following set of FD's Find set of O's Ears (1) Wz evar, esau eaaUeeaeaeaye eee a) Va] ek pasate (3) (Wz) 4) {WZ} > Y renee @ Dr Assadipour Page 8 Determine the redundant FD’s Testing (1): v Remove W -» Z from the set of FD's ¥ Setresult + W ¥ Since from #2, WY and Wis in result then result¢- WU Y> WUY={W, Y} ¥ Searching for a FD in which {W, Y} is determinant produces no results. ¥ Therefore we are unable to show that Z is contained in the result. ¥ Conclusion is: FD (1) is not redundant. Testing (2): Can conclude that FD #2 is redundant. Testing (3): Not redundant. Testing (4): Not redundant. Norm: A) dt: A + {C,E,F,G} P14 includes all attributes in R. d2: B + {D,H,1} aS ACAB => (AB)'={A,B, C,D,E,F,G,H, d3: HI “> (AB) <> Cust_No & Prop_No 8 d4: A> C Assume single family home a ES NE @ Dr Assadipour Page 9 8) aa it partial al A B c D E F 6 Cust.No PropNo Cust_Name P_Add Rent Siatt RenlEnd Rent O_No ©_Name H f | qi 8 a per a Ri: {A, B, C, D, E, F, G} Remove partial Re: {B, DH, dependencies D) 3 NF: R3: (A, C} R4: {B, E, F, A} | RS: {B, D, G, H} ae R6: {H, |} Customer Owner A —»[H [I | Property — Rent [po Te eI t_ Rental E F @ Dr Assadipour Page 10

You might also like