Presentation is loading. Please wait.

Presentation is loading. Please wait.

Rob Gleasure R.Gleasure@ucc.ie www.robgleasure.com IS6145 Database Analysis and Design Lecture 9: Normalization of Data Tables Rob Gleasure R.Gleasure@ucc.ie.

Similar presentations


Presentation on theme: "Rob Gleasure R.Gleasure@ucc.ie www.robgleasure.com IS6145 Database Analysis and Design Lecture 9: Normalization of Data Tables Rob Gleasure R.Gleasure@ucc.ie."— Presentation transcript:

1 Rob Gleasure R.Gleasure@ucc.ie www.robgleasure.com
IS6145 Database Analysis and Design Lecture 9: Normalization of Data Tables Rob Gleasure

2 Course structure Or more specifically Week 1: Introduction
Week 2: Foundational Concepts of Data Modelling Week 3: ER Modelling and Beyond the Presentation Layer Week 4: Fine-Granular Design-Specific ER Modelling Week 5: Enhanced Entity-Relationship (EER) Modelling Week 6: Practice with ERDs Week 7: In-Class Data Modelling Exam Week 8: The Data Value Map Week 9: Data Normalisation Week 10: NoSQL and Hadoop Week 11: Blockchain Week 12: Revision

3 Using tables Image from

4 A note on attribute naming
In ER model, the same attribute name is allowed to appear in different entity types since they imply different roles for the attribute name – this duplication is not something we want to carry over to our tables The easiest way to do this is just to add a relation-specific prefix to the name of all attributes for that table, e.g. instead of ‘licence’ we name the attribute ‘car_licence’

5 Constraints Primary key Has to have three qualities Unique Irreducible
Never null

6 ER to Table Mapping For each strong (regular) entity type
Create a table Create an attribute for every attribute of the corresponding entity type. Note that: For composite attributes only their constituent atomic components are recorded Derived attributes are not recorded Choose a primary key

7 ER to Table Mapping (continued)
Example of mapping strong entity Ch_name Ch_age

8 ER to Table Mapping (continued)
For each weak entity type, Create a table Create an attribute in each schema for every attribute of the corresponding entity type Add the primary key of the identifying parent entity type as attribute(s) in the table schema. The attribute(s) thus added plus the partial key of the weak entity type form the primary key of the table representing the weak entity type

9 ER to Table Mapping (continued)
Example of mapping weak entity  FORM (strong entity)  SPECIAL NEED Fm_form_ID Fm_contact Fm_name Sn_need Sn_Fm_form_ID Sn_Fm_contact

10 ER to Relational Mapping
For each relationship Identify the referencing schema (the child in the relationship) Where relationships are one-to-many, the referencing schema will be the on the ‘many’ side Where relationships are one-to-one, just pick the one that makes sense Enforce a foreign key constraint between the tables participating in the relationship type Note: The attribute will have to be optional if the relationship is zero-to-one or zero-to-many

11 ER to Relational Mapping
Example of mapping relationship  CHILD  ROOM Ch_name Ch_Age Ch_Rm_name Rm_name Rm_Size

12 Normalization!

13 Inferring Functional Dependencies (The Armstrong Axioms)
1. Reflexivity: If Y is a subset of X, then X Y 2. Augmentation: If X Y, then XZ YZ 3: Transitivity: If X Y, and Y Z, then X Z

14 Normalisation: Orders Table
Full_ Name Address Zone Order _ID Date Product_1 Cost_P1 Units_P1 Product_2 Cost_P2 Units_P2 Product_3 Cost_P3 Units_ P3 John Murphy 123 Fake St Inner-city S345 31/12/ 2014 Football $20.00 2 Gloves $53.50 1 Whistle $5.00 Mary Byrne Kildaman-fadar Rural R367 9/9/ Helmet $30.50 Anne Dunne N654 10/6/ Pants $13.75 Hat $11.00 Jim Feltz 20c Fake St D896 13/06/ $28.75 Boots $75.95 S354 1/01/ 2015 Socks $3.50 5

15 Normalisation: First Normal Form
Name Address Zone Order _ID Date Product Cost Units John Murphy 123 Fake St Inner-city S345 31/12/ 2014 Football $20.00 2 Gloves $53.50 1 Whistle $5.00 S354 Socks $3.50 5 Mary Byrne Kildaman-fadar Rural R367 9/9/ Helmet $30.50 Anne Dunne N654 10/6/ Pants $13.75 Hat $11.00 Jim Feltz 20c Fake St D896 13/06/ $28.75 Boots $75.95

16 First Normal Form (continued)
Name Last_ Address Zone Order _ID Date Product Cost Units John Murphy 123 Fake St Inner-city S345 31/12/ 2014 Football $20.00 2 Gloves $53.50 1 Whistle $5.00 S354 Socks $3.50 5 Mary Byrne Kildaman-fadar Rural R367 9/9/ Helmet $30.50 Anne Dunne N654 10/6/ Pants $13.75 Hat $11.00 Jim Feltz 20c Fake St D896 13/06/ $28.75 Boots $75.95

17 Summary of First Normal Form (1NF)
A database is in the first normal form when Attributes store only atomic values Duplicate columns are removed

18 Moving to Second Normal Form
First_ Name Last_ Address Zone Order _ID Date Product Cost Units John Murphy 123 Fake St Inner-city S345 31/12/ 2014 Football $20.00 2 Gloves $53.50 1 Whistle $5.00 S354 Socks $3.50 5 Mary Byrne Kildaman-fadar Rural R367 9/9/ Helmet $30.50 Anne Dunne N654 10/6/ Pants $13.75 Hat $11.00 Jim Feltz 20c Fake St D896 13/06/ $28.75 Boots $75.95

19 Second Normal Form Cust_ID Order _ID Date Product Cost Units Cust_ID
1 S345 31/12/ 2014 Football $20.00 2 Gloves $53.50 Whistle $5.00 S354 Socks $3.50 5 R367 9/9/ Helmet $30.50 3 N654 10/6/ Pants $13.75 Hat $11.00 4 D896 13/06/ $28.75 Boots $75.95 Cust_ID First_ Name Last_ Address Zone 1 John Murphy 123 Fake St Inner-city 2 Mary Byrne Kildaman-fadar Rural 3 Anne Dunne 4 Jim Feltz 20c Fake St

20 Second Normal Form (Continued)
Cust_ ID Order _ID Date Product Units 1 S345 31/12/ 2014 2 3 S354 4 5 R367 9/9/ N654 10/6/ 6 7 D896 13/06/ 8 Cust_ ID First_ Name Last_ Address Zone 1 John Murphy 123 Fake St Inner-city 2 Mary Byrne Kildaman-fadar Rural 3 Anne Dunne 4 Jim Feltz 20c Fake St Product_ID Product_1 Cost_P1 1 Football $20.00 2 Gloves $53.50 3 Whistle $5.00 4 Socks $3.50 5 Helmet $30.50 6 Pants $13.75 7 Hat $11.00 8 Boots $75.95

21 Second Normal Form (Continued)
Cust_ID Order _ID Product Units 1 S345 2 3 S354 4 5 R367 N654 6 7 D896 8 Cust_ ID First_ Name Last_ Address Zone 1 John Murphy 123 Fake St Inner-city 2 Mary Byrne Kildaman-fadar Rural 3 Anne Dunne 4 Jim Feltz 20c Fake St Order _ID Date S345 31/12/ 2014 S354 R367 09/09/ N654 10/6/ D896 13/06/ Product_ID Product_1 Cost_P1 1 Football $20.00 2 Gloves $53.50 3 Whistle $5.00 4 Socks $3.50 5 Helmet $30.50 6 Pants $13.75 7 Hat $11.00 8 Boots $75.95

22 Second Normal Form (Continued)
Order _ID Product Units S345 1 2 3 S354 4 5 R367 N654 6 7 D896 8 Cust_ ID First_ Name Last_ Address Zone 1 John Murphy 123 Fake St Inner-city 2 Mary Byrne Kildaman-fadar Rural 3 Anne Dunne 4 Jim Feltz 20c Fake St Order _ID Date Cust_ ID S345 31/12/ 2014 1 S354 R367 09/09/ 2 N654 10/6/ 3 D896 13/06/ 4 Product_ID Product_1 Cost_P1 1 Football $20.00 2 Gloves $53.50 3 Whistle $5.00 4 Socks $3.50 5 Helmet $30.50 6 Pants $13.75 7 Hat $11.00 8 Boots $75.95

23 Summary of Second Normal Form (2NF)
A database is in the second normal form when It satisfies the criteria for the first normal form Each non-candidate key is dependent on the whole candidate key (i.e. subsets of data across multiple rows are removed) Put differently, we have no partial dependencies via a concatenated key Takes advantage of reflexivity and augmentation

24 Moving to Third Normal Form
Order _ID Product Units S345 1 2 3 S354 4 5 R367 N654 6 7 D896 8 Cust_ ID First_ Name Last_ Address Zone 1 John Murphy 123 Fake St Inner-city 2 Mary Byrne Kildaman-fadar Rural 3 Anne Dunne 4 Jim Feltz 20c Fake St Order _ID Date Cust_ ID S345 31/12/ 2014 1 S354 R367 09/09/ 2 N654 10/6/ 3 D896 13/06/ 4 Product_ID Product_1 Cost_P1 1 Football $20.00 2 Gloves $53.50 3 Whistle $5.00 4 Socks $3.50 5 Helmet $30.50 6 Pants $13.75 7 Hat $11.00 8 Boots $75.95

25 Moving to Third Normal Form
Order _ID Product Units S345 1 2 3 S354 4 5 R367 N654 6 7 D896 8 Address Zone 123 Fake St Inner-city 20c Fake St Kildaman-fadar Rural Cust_ ID First_ Name Last_ Address 1 John Murphy 123 Fake St 2 Mary Byrne Kildaman-fadar 3 Anne Dunne 4 Jim Feltz 20c Fake St Order _ID Date Cust_ ID S345 31/12/ 2014 1 S354 R367 09/09/ 2 N654 10/6/ 3 D896 13/06/ 4 Product_ID Product_1 Cost_P1 1 Football $20.00 2 Gloves $53.50 3 Whistle $5.00 4 Socks $3.50 5 Helmet $30.50 6 Pants $13.75 7 Hat $11.00 8 Boots $75.95

26 Summary of Third Normal Form (3NF)
A database is in the second normal form when It satisfies the criteria for the second normal form Each non-key attribute that depends on anything other than the entire primary key is removed (insertion anomalies are impossible) Put differently, we have no transitive dependencies via non-key attributes Takes advantage of transitivity

27 Normalisation example
Table of doctor’s appointments Patient ID Name Contact Emergency contact Appointments Procedures Paid Notes John Smith Jane Smith, 15th Dec 2017 28th Dec 2017 1st Jan 2018 Check-up Eye exam Yes No Allergic to penicillin Margaret Dunning Mary Alves, 21st Jan 2018 3rd Mar 2018 Surgery None Elizabeth Cartmond Fred Cartmond, 4th Apr 2018 11th Apr 2018 Tests Follow-up Claustrophobic

28 Normalisation example: 1st NF
Patient ID Fname Lname Contact Emergency name Emergency number Appointment s Procedures Paid Notes John Smith Jane Smith 15th Dec Check-up Yes Allergic to penicillin 28th Dec No 1st Jan 2018 Eye exam Margaret Dunning Mary Alves 21st Jan 2018 Surgery None 3rd Mar 2018 Elizabeth Cartmond Fred Cartmond 4th Apr 2018 Tests Claustro- phobic 11th Apr 2018 Follow-up

29 Normalisation example: 2nd NF
Patient ID Fname Lname Contact Emergency name Emergency number Notes John Smith Jane Smith Allergic to penicillin Margaret Dunning Mary Alves None Elizabeth Cartmon d Fred Cartmond Claustro- phobic Patient ID Appointme nts Procedure s Paid 15th Dec Check-up Yes 28th Dec No 1st Jan 2018 Eye exam 21st Jan Surgery 3rd Mar 4th Apr Tests 11th Apr Follow- up

30 Normalisation example: 3rd NF
Patient ID Fname Lname Contact Emergency number Notes John Smith Allergic to penicillin Margaret Dunning None Elizabeth Cartmond Claustro- phobic Patient ID Appointments Procedures Paid 15th Dec 2017 Check-up Yes 28th Dec 2017 No 1st Jan 2018 Eye exam 21st Jan 2018 Surgery 3rd Mar 2018 4th Apr 2018 Tests 11th Apr 2018 Follow-up Emergency number Emergency name Jane Smith Mary Alves Fred Cartmond

31 Normalisation (Winter 2016)
Table 1. Database for train bookings Name Ticket type Amendable Journey Duration Departure Nationality EU Ben Feringa Monthly pass Yes Paris to Munich 4 hours 15/01/ Berlin to Vienna 2.5 hours 25/01/ Netherlands May-Britt Moser One-way No Barcelona to Madrid 3 hours 03/02/ Norway Alice Munro Return 20/01/ Munich to Paris 12/03/ Canada Yoshinori Ohsumi Milan to Bucharest 5 hours Bucharest to Krakow 9 hours 20/02/ Japan

32 Normalisation (Winter 2016)
1st normal form FName LName Ticket type Amendable Journey Duration Departure National-ity EU Ben Feringa Monthly pass Yes Paris to Munich 4 hours 15/01/ Nether-lands Berlin to Vienna 2.5 hours 25/01/ May-Britt Moser One-way No Barcelona to Madrid 3 hours 03/02/ Norway Alice Munro Return 20/01/ Canada Munich to Paris 12/03/ Yoshinori Ohsumi Milan to Bucharest 5 hours Japan Bucharest to Krakow 9 hours 20/02/

33 Normalisation (Winter 2016)
2nd normal form Passenger ID Ticket type Journey Departure 1 Monthly pass Paris to Munich 15/01/ Berlin to Vienna 25/01/ 2 One-way Barcelona to Madrid 03/02/ 3 Return 20/01/ Munich to Paris 12/03/ 4 Milan to Bucharest Bucharest to Krakow 20/02/ Passenger ID First name Last name Nationality EU 1 Ben Feringa Netherlands Yes 2 May-Britt Moser Norway No 3 Alice Munro Canada 4 Yoshinori Ohsumi Japan Ticket type Amendable Monthly pass Yes One-way No Return Paris to Munich 4 hours Berlin to Vienna 2.5 hours Barcelona to Madrid 3 hours Munich to Paris Milan to Bucharest 5 hours Bucharest to Krakow 9 hours

34 Normalisation (Winter 2016)
3rd normal form Passenger ID Ticket type Journey Departure 1 Monthly pass Paris to Munich 15/01/ Berlin to Vienna 25/01/ 2 One-way Barcelona to Madrid 03/02/ 3 Return 20/01/ Munich to Paris 12/03/ 4 Milan to Bucharest Bucharest to Krakow 20/02/ Passenger ID First name Last name Nationality 1 Ben Feringa Netherlands 2 May-Britt Moser Norway 3 Alice Munro Canada 4 Yoshinori Ohsumi Japan Nationality EU Netherlands Yes Norway No Canada Japan Ticket type Amendable Monthly pass Yes One-way No Return Paris to Munich 4 hours Berlin to Vienna 2.5 hours Barcelona to Madrid 3 hours Munich to Paris Milan to Bucharest 5 hours Bucharest to Krakow 9 hours

35 Readings Some more descriptions of normal forms


Download ppt "Rob Gleasure R.Gleasure@ucc.ie www.robgleasure.com IS6145 Database Analysis and Design Lecture 9: Normalization of Data Tables Rob Gleasure R.Gleasure@ucc.ie."

Similar presentations


Ads by Google