Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unnormalized Form (UNF) student courses John CS363 CS334 CS323 Multi-Value attribute Common in reports 1.

Similar presentations


Presentation on theme: "Unnormalized Form (UNF) student courses John CS363 CS334 CS323 Multi-Value attribute Common in reports 1."— Presentation transcript:

1 Unnormalized Form (UNF) student courses John CS363 CS334 CS323 Multi-Value attribute Common in reports 1

2 First Normal Form (1NF) No multi-value attributes Done when mapping E-R model to relational schema 2

3 Second Normal Form (2NF) A relation R is in 1NF, and every non-primary-key attribute is fully functionally dependent on the primary key Then R is in 2NF No Partial FDs on the PK. 3

4 4 Partial FDs If X, W Y and X Y Then X, W Y is a partial FD Example: Sno, Bno staffAddress, staffPhone Sno staffAddress, staffPhone

5 5 Full FDs A FD is a full FD if its not partial. A, B X, Y is a full FD if A X, Y is false B X, Y is false Sno staffAddress, staffPhone Pno, Start Rno, Rent, End

6 Example Lease (RNo, RName, PNo, PAddress, Start, Finish, Rent, ONo, OName) Primary Key: PNo, Start Alternate Key: PNo, Finish PAddress, Start PAddress, Finish FDs: PNo, Start ---> All other attributes PNo, Finish ---> All other attributes PAddress, Start ---> All other attributes PAddress, Finish ---> All other attributes PNo ---> PAddress, ONo, OName (Partial on Primary Key) PAddress ---> PNo, ONo, OName RNo ---> RName ONo ---> Oname 6

7 Table Instance RNo RName PNo PAddress Start Finish Rent Ono OName R101 John P main O100 Tina R102 Mike P main O100 Tina R103 Kay P main O100 Tina R101 John P main O110 Tony R105 Scot P first O109 Tony PNo, Start ---> All other attributes (Partial on Primary Key) PNo ---> PAddress, ONo, OName Not in 2NF! Poor Performance Redundancy Inconsistency 7

8 Decompose Lease into 2NF Lease (RNo, RName, PNo, PAddress, Start, Finish, Rent, ONo, OName) Primary Key: PNo, Start Partial FD on Primary Key PNo ---> PAddress, ONo, OName Remove partial dependent on Primary Key Create a new relation Which attributes are in the new relation? All attributes in (both side of) the partial FD Lease1 (PNo, PAddress, ONo, OName) Which attributes are left in the original relation? PK remains the same Lease2 (RNo, RName, PNo, Start, Finish, Rent) PK and FK? 8

9 Lease1 (PNo, PAddress, ONo, OName) Primary Key: PNo Alternate Key: PAddress Foreign Key: None (from this conversion Functional Dependencies: PNo ---> All other attributes PAddress ---> PNo, ONo, OName ONo ---> OName In 2NF? Lease2 (RNo, RName, PNo, Start, Finish, Rent) Primary Key: PNo, Start Alternate Key: PNo, Finish Foreign Key: PNo references Lease1 Functional Dependencies: PNo, Start ---> All other attributes PNo, Finish ---> All other attributes RNo ---> Rname In 2NF? 9

10 Relation/Table Instances Lease Rno RName PNo PAddress Start Finish Rent Ono OName R101 John P main O100 Tina R102 Mike P main O100 Tina R103 Kay P main O100 Tina R101 John P main O110 Tony R105 Scot P first O109 Tony Lease1 PNo PAddress ONo OName P main O100 Tina P main O110 Tony P first O109 Tony Lease1 = PNo, PAddress, Ono, OName (Lease) 10

11 Removing Duplicates Lease1 PNo PAddress ONo OName P main O100 Tina P main O110 Tony P first O109 Tony Lease1 P main O100 Tina P main O110 Tony P first O109 Tony 11

12 Lease RNo RName PNo PAddress Start Finish Rent Ono OName R101 John P main O100 Tina R102 Mike P main O100 Tina R103 Kay P main O100 Tina R101 John P main O110 Tony R105 Scot P first O109 Tony Lease2 RNo RName PNo Start Finish Rent R101 John P R102 Mike P R103 Kay P R101 John P R105 Scot P Lease2 = RNo, RName, RNo, Start, Finish, Rent (Lease) 12

13 Some FDs are lost Lease (RNo, RName, PNo, PAddress, Start, Finish, Rent, ONo, OName) PAddress, Start ---> All other attributes PAddress, Finish ---> All other attributes Lease1 (PNo, PAddress, ONo, OName) Lease2 (RNo, RName, PNo, Start, Finish, Rent) 13

14 Example Relation R (A, B, C, D, E, F) Primary Key: A, B Alternate Key: None Foreign Key: None Functional Dependencies: A, B ---> All A ---> C B ---> E, F In 2NF? NO! 14

15 Table Instance A B C D E F 1 x cs se 1 y cs ee 2 x cs se 2 y cs ee Functional Dependencies: A, B ---> All A ---> C B ---> E, F 15

16 R1 (A, C) Primary Key: A Alternate Key: None Foreign Key: None Functional Dependencies: A ---> C R2 (B, E, F) Primary Key: B Alternate Key: None Foreign Key: None Functional Dependencies: B ---> E, F R3 (A, B, D) Primary Key: A, B Alternate Key: None Foreign Key: A References R1 B References R2 Functional Dependencies: A, B ---> D 16 R (A, B, C, D, E, F) Functional Dependencies: A, B ---> All A ---> C B ---> E, F Decompose table R into 2NF

17 Table Instance R A B C D E F 1 x cs se 1 y cs ee 2 x cs se 2 y cs ee R1 A C R2 B E F x cs se y cs ee R3 A B D 1 x y x y


Download ppt "Unnormalized Form (UNF) student courses John CS363 CS334 CS323 Multi-Value attribute Common in reports 1."

Similar presentations


Ads by Google