Download presentation
Presentation is loading. Please wait.
Published byWarren Pearson Modified over 9 years ago
1
Tutorial 6: normalize the following relation to 1NF, 2NF, and 3NF TransIDRentDateCustomerIDLastNamePhoneAddressVideoIDCopy#TitleRent 14/18/043Washington502-777-757595 Easy Street122001: A Space Odyssey$1.50 14/18/04 3Washington502-777-757595 Easy Street63Clockwork Orange$1.50 24/30/04 7Lasater615-888-447467 S. Ray Drive81Hopscotch$1.50 24/30/04 7Lasater615-888-447467 S. Ray Drive21Apocalypse Now$2.00 24/30/04 7Lasater615-888-447467 S. Ray Drive61Clockwork Orange$1.50 34/18/048Jones615-452-1162867 Lakeside Drive91Luggage Of The Gods$2.50 34/18/04 8Jones615-452-1162867 Lakeside Drive151Fabulous Baker Boys$2.00 34/18/04 8Jones615-452-1162867 Lakeside Drive41Boy And His Dog$2.50 44/18/043Washington502-777-757595 Easy Street31Blues Brothers$2.00 44/18/04 3Washington502-777-757595 Easy Street81Hopscotch$1.50 44/18/04 3Washington502-777-757595 Easy Street131Surf Nazis Must Die$2.50 44/18/043Washington502-777-757595 Easy Street171Witches of Eastwick$2.00 RentalForm(TransID, RentDate, CustomerID, Phone, Name, Address, City, State, ZipCode, Video(VideoID, Copy#, Title, Rent ) )
2
First Normal Form RentalForm(TransID, RentDate, CustomerID, Phone, Name, Address, City, State, ZipCode, (VideoID, Copy#, Title, Rent ) ) RentalForm2(TransID, RentDate, CustomerID, Phone, Name, Address, City, State, ZipCode) RentalLine(TransID, VideoID, Copy#, Title, Rent ) u Remove repeating sections –Split into two tables –Bring key from main and repeating section u RentalLine(TransID, VideoID, Copy#,...) –Each transaction can have many videos (key VideoID) –Each video can be rented on many transactions (key TransID) –For each TransID and VideoID, only one Copy# (no key on Copy#)
3
1NF: TransID RentDateCustIDPhoneLastNameFirstNameAddressCityStateZipCode 14/18/043502-777-7575WashingtonElroy95 Easy StreetSmith's GroveKY42171 24/30/047615-888-4474LasaterLes67 S. Ray DrivePortlandTN37148 34/18/048615-452-1162JonesCharlie867 Lakeside DriveCastalian SpringsTN37031 44/18/043502-777-7575WashingtonElroy95 Easy StreetSmith's GroveKY42171 TransIDVideoIDCopy#TitleRent 1122001: A Space Odyssey$1.50 163Clockwork Orange$1.50 281Hopscotch$1.50 221Apocalypse Now$2.00 261Clockwork Orange$1.50 391Luggage Of The Gods$2.50 3151Fabulous Baker Boys$2.00 341Boy And His Dog$2.50 431Blues Brothers$2.00 481Hopscotch$1.50 4131Surf Nazis Must Die$2.50 4171Witches of Eastwick$2.00
4
Second Normal Form Definition u Each non-key column must depend on the entire key. –Only applies to concatenated keys –Some columns only depend on part of the key –Split those into a new table. RentalLine(TransID, VideoID, Copy#, Title, Rent) Depend only on VideoID Depends on both TransID and VideoID
5
Second Normal Form Example u Title depends only on VideoID –Each VideoID can have only one title u Rent depends on VideoID –This statement is actually a business rule. –It might be different at different stores. –Some stores might charge a different rent for each video depending on the day (or time). u Each non-key column depends on the whole key. RentalLine(TransID, VideoID, Copy#, Title, Rent) VideosRented(TransID, VideoID, Copy#) Videos(VideoID, Title, Rent)
6
Second Normal Form Example (Data) TransIDVideoIDCopy# 112 163 221 261 281 341 391 3151 431 481 4131 4171 VideoIDTitleRent 12001: A Space Odyssey$1.50 2Apocalypse Now$2.00 3Blues Brothers$2.00 4Boy And His Dog$2.50 5Brother From Another Planet$2.00 6Clockwork Orange$1.50 7Gods Must Be Crazy$2.00 8Hopscotch$1.50 VideosRented(TransID, VideoID, Copy#) Videos(VideoID, Title, Rent) RentalForm2(TransID, RentDate, CustomerID, Phone, Name, Address, City, State, ZipCode) (Unchanged)
7
Second Normal Form Problems (Data) TransIDRentDateCustIDPhoneLastNameFirstNameAddressCityStateZipCode 14/18/043502-777-7575WashingtonElroy95 Easy StreetSmith's GroveKY42171 24/30/047615-888-4474LasaterLes67 S. Ray DrivePortlandTN37148 34/18/048615-452-1162JonesCharlie867 Lakeside DriveCastalian SpringsTN37031 44/18/0423502-777-7575WashingtonElroy95 Easy StreetSmith's GroveKY42171 RentalForm2(TransID, RentDate, CustomerID, Phone, Name, Address, City, State, ZipCode) u Even in 2NF, problems remain –Redundancy (Replication) –Hidden dependency –If a customer has not rented a video yet, where do we store their personal data? u Solution: split table.
8
Third Normal Form Definition RentalForm2(TransID, RentDate, CustomerID, Phone, Name, Address, City, State, ZipCode) u Each non-key column must depend on nothing but the key. –Some columns depend on columns that are not part of the key. –Split those into a new table. –Example: Customers name does not change for every transaction. u Dependence (definition) –If given a value for the key you always know the value of the property in question, then that property is said to depend on the key. –If you change the key and the questionable property does not change, then the table is not in 3NF. Depend only on CustomerID Depend on TransID
9
Third Normal Form Example u Customer attributes depend only on Customer ID –Split them into new table (Customer) –Remember to leave CustomerID in Rentals table. –We need to be able to reconnect tables. u 3NF is sometimes easier to see if you identify primary objects at the start--then you would recognize that Customer was a separate object. RentalForm2(TransID, RentDate, CustomerID, Phone, Name, Address, City, State, ZipCode) Rentals(TransID, RentDate, CustomerID ) Customers(CustomerID, Phone, Name, Address, City, State, ZipCode )
10
Third Normal Form Example Data TransIDRentDateCustomerID 14/18/04 3 24/30/04 7 34/18/048 44/18/043 CustomerIDPhoneLastNameFirstNameAddressCityStateZipCode 1502-666-7777JohnsonMartha125 Main StreetAlvatonKY42122 2502-888-6464SmithJack873 Elm StreetBowling GreenKY42101 3502-777-7575WashingtonElroy95 Easy StreetSmith's GroveKY42171 4502-333-9494AdamsSamuel746 Brown DriveAlvatonKY42122 5502-474-4746RabitzVictor645 White AvenueBowling GreenKY42102 6615-373-4746SteinmetzSusan15 Speedway DrivePortlandTN37148 7615-888-4474LasaterLes67 S. Ray DrivePortlandTN37148 8615-452-1162JonesCharlie867 Lakeside DriveCastalian TN37031 9502-222-4351ChavezJuan673 Industry Blvd.CaneyvilleKY42721 10502-444-2512RojoMaria88 Main StreetCave CityKY42127 Rentals(TransID, RentDate, CustomerID ) Customers(CustomerID, Phone, Name, Address, City, State, ZipCode ) VideosRented(TransID, VideoID, Copy#) Videos(VideoID, Title, Rent) RentalForm2(TransID, RentDate, CustomerID, Phone, Name, Address, City, State, ZipCode
11
Exercise : Put the following on the 1NF, 2NF and 3NF
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.