CS 3630 Database Design and Implementation
Unnormalized Form (UNF) student courses Joe Clifton CS3630 CS3340 CS3230 Multi-Value attribute Common in reports 2NF and 3NF could be in one note.
First Normal Form (1NF) No multi-value attributes Done when mapping E-R model to relational schema DBDL
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.
Partial FDs X, Y W is a partial FD if X W or Y W is true Lease (RNo, RName, PNo, PAddress, Start, Finish, Rent, ONo, OName) PAddress, Start All PAddress, Start PNo, ONo, OName PAddress PNo, ONo, OName
Second Normal Form (2NF) No Partial FDs on the PK. PK All other attributes Assume a table with a simple PK of Att1 Att1 All other attributes Is it in 2NF? Cannot have partial FD on simple PK Assume a table with a composite PK of Att1 and Att2 Att1, Att2 Att3, Att4, Att5 (All other attributes) It’s possible Att2 Att5 Att1, Att2 Att3, Att4
Example Lease (RNo, RName, PNo, PAddress, Start, Finish, Rent, ONo, OName) PK: PNo, Start AK: PNo, Finish PAddress, Start PAddress, Finish FDs: PNo, Start All PNo, Finish All PAddress, Start All PAddress, Finish All RNo RName ONo Oname PAddress PNo, ONo, OName PNo PAddress, ONo, OName Partial FD on Primary Key?
Table Instance Not in 2NF! Poor Performance Redundancy Inconsistency RNo RName PNo PAddress Start Finish Rent Ono OName R101 John P1001 1001 main 1-1-04 12-31-04 350 O100 Tina R102 Mike P1001 1001 main 1-1-05 2-28-05 380 O100 Tina R103 Kay P1001 1001 main 3-1-05 12-31-05 380 O100 Tina R101 John P1002 2001 main 1-1-05 12-31-05 550 O110 Tony R105 Scot P1009 1009 first 1-1-04 5-31-04 350 O109 Tony PNo, Start All other attributes (Partial on Primary Key) PNo PAddress, ONo, OName Not in 2NF! Poor Performance Redundancy Inconsistency What to Do? Move the attributes to another table!
Decompose Lease into 2NF Lease (RNo, RName, PNo, PAddress, Start, Finish, Rent, ONo, OName) PK: 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 the partial FD (both side of) Lease1 (PNo, PAddress, ONo, OName) Which attributes are left in the original relation? PK remains the same Lease (RNo, RName, PNo, Start, Finish, Rent) PK? FK?
Lease1 (PNo, PAddress, ONo, OName) PK: PNo AK: PAddress FK: None (from this conversion) Functional Dependencies: PNo All other attributes PAddress PNo, ONo, OName ONo OName In 2NF? Lease (RNo, RName, PNo, Start, Finish, Rent) PK: PNo, Start AK: PNo, Finish FK: PNo references Lease1 Functional Dependencies: PNo, Start All other attributes PNo, Finish All other attributes RNo Rname In 2NF?
Relation/Table Instances Lease Rno RName PNo PAddress Start Finish Rent Ono OName R101 John P1001 1001 main 1-1-04 12-31-04 350 O100 Tina R102 Mike P1001 1001 main 1-1-05 2-28-05 380 O100 Tina R103 Kay P1001 1001 main 3-1-05 12-31-05 380 O100 Tina R101 John P1002 2001 main 1-1-05 12-31-05 550 O110 Tony R105 Scot P1009 1009 first 1-1-04 5-31-04 350 O109 Tony Lease1 PNo PAddress ONo OName P1001 1001 main O100 Tina P1002 2001 main O110 Tony P1009 1009 first O109 Tony PNo, PAddress, Ono, OName (Lease)
Removing Duplicates Lease1 PNo PAddress ONo OName P1001 1001 main O100 Tina P1002 2001 main O110 Tony P1009 1009 first O109 Tony P1001 1001 main O100 Tina P1002 2001 main O110 Tony P1009 1009 first O109 Tony
Lease (before) Lease (after) RNo RName PNo Start Finish Rent RNo RName PNo PAddress Start Finish Rent Ono OName R101 John P1001 1001 main 1-1-04 12-31-04 350 O100 Tina R102 Mike P1001 1001 main 1-1-05 2-28-05 380 O100 Tina R103 Kay P1001 1001 main 3-1-05 12-31-05 380 O100 Tina R101 John P1002 2001 main 1-1-05 12-31-05 550 O110 Tony R105 Scot P1009 1009 first 1-1-04 5-31-04 350 O109 Tony Lease (after) RNo RName PNo Start Finish Rent R101 John P1001 1-1-04 12-31-04 350 R102 Mike P1001 1-1-05 2-28-05 380 R103 Kay P1001 3-1-05 12-31-05 380 R101 John P1002 1-1-05 12-31-05 550 R105 Scot P1009 1-1-04 5-31-04 350 RNo, RName, RNo, Start, Finish, Rent (Lease)
Some FDs are lost Lease (RNo, RName, PNo, PAddress, Start, Finish, Rent, ONo, OName) PAddress, Start All PAddress, Finish All Lease1 (PNo, PAddress, ONo, OName) Lease (RNo, RName, PNo, Start, Finish, Rent)
Assignment 5-1
Assumptions Identify all non-trivial FDs NIN eName contractNo hNo, hLoc hNo hLoc NIN, contractNo All ( NIN, contractNo hours) Choose a PK: NIN, contractNo List all AKs: NONE
Schedule Assignment 61 Due Thursday, March 1, by 5 pm Quiz 2 Wednesday, March 7 Covers A4 and A51, A61
Assignment 4