Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

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

2 IS6125 Today’s session What did we learn from the reports?
Creating tables from ERDs Normalisation

3 Themes to reflect on with the reports
Three Vs Datafication and the Internet of Things Recording things is the first step Information asymmetry It’s bad for a market when one side knows more than the other about the quality of specific instances Privacy Data has value to a consumer Different types of data Self-reported data Trace/exhaust data Profiling data

4 Using tables Image from

5 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’

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

7 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

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

9 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

10 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

11 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

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

13 Normalization!

14 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

15 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

16 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

17 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

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

19 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

20 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

21 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

22 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

23 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

24 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

25 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

26 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

27 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

28 Readings Some more descriptions of normal forms


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

Similar presentations


Ads by Google