Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Design Chapter 9 Part-2: Normalization 1.

Similar presentations


Presentation on theme: "Database Design Chapter 9 Part-2: Normalization 1."— Presentation transcript:

1 Database Design Chapter 9 Part-2: Normalization 1

2  Part Two Normalization − 1NF − 2NF − 3NF Integrity Controls Outline 2

3 3 Study the problems with this table. This is why we need Normalization ! Appointment Table Carla called to inquire about her appointment time on 12/2/2015. She also gives us her new phone number: 777-1234 Update Anomaly Mike called to cancel his appointment. Delete Anomaly Sue calls to make another appointment for December 15 th. Insert Anomaly Appt No Appt Date Appt Time Planned Duration Appt Type Patient ID First Nm Last NmPhone Doctor ID Doctor Nm 112/1/20153:00 AM1.00Physical466927LisaGarcia562-3456C678Chapman 212/1/20153:00 AM0.25Shot456789SueCarey432-1234A528Lopez 312/1/20153:15 AM0.50Flu194756BrandonPierre432-7877S626Smith 412/2/201510:00 AM0.50Migraine329657MarcusSchwartz239-5502A528Lopez 512/2/201510:15 AM0.25Shot987453MikeJones456-0202G123Gray 612/2/201510:30 AM0.25Shot384788TonyaJohnson432-8806S626Smith 712/2/201510:45 AM0.50Flu438754IlianaHnatt823-4303C678Chapman 812/2/201511:00 AM1.00Physical345875CarlaBasich857-5566A528Lopez 912/3/201510:30 AM1.00Physical466927LisaGarcia562-3456C678Chapman 1012/3/20159:00 AM0.50Migraine345875CarlaBasich857-5566C678Chapman 12/2/2015

4  (def) the process of converting complex data structures into simple, stable data structures. 4 Normalization Purpose: Create well-structured relations/tables Why?  Data Redundancy =  Data Quality & Integrity Result: where we can insert, modify, and delete the rows without errors or inconsistencies. Every non-primary key attribute depends upon the whole primary key and nothing but the primary key.

5 Normalization Normal Form Definition 1NF The table has no repeating fields or groups of fields 2NF No Partial Dependencies! The table is in 1NF, and … every non-key attribute is functionally dependent on the entire primary key 3NF No Transitive Dependencies! The table is in 2NF, and … each non-key attribute is not functionally dependent on another non-key attribute

6  The table has: No multi-valued attributes − EMP (ssn, name, dept, sal, dependents) No repeating fields or groups of fields − EMP (ssn, name, dept, sal, dep1, dep2, dep3, … depN) 6 First Normal Form (1NF)

7 Alternatively, it can be read as “Field B determines Field A” − If we know the value of B, we can obtain the value of A. Functional Dependency involves a one-to-one relationship between the values of fields EmpNo  Salary Salary  EmpNo  StudentId  Name HomeTown  LastName  Notes: − Sample Data does not prove the existence of a functional dependency. − Knowledge of problem domain is critical! 7 Functional Dependency Field A is functionally dependent on Field B if for each value of B, there is only 1 corresponding value of A B  A

8  in 1NF and if each non-key attribute is functionally dependent on entire primary key 8 Second Normal Form (2NF) Need a new table since CatIssueDate is determined only by ______________ What is the PK? ______________ 1NF 2NF

9  in 2NF and if no non-key attribute is functionally dependent on any other non-key attribute 9 Third Normal Form (3NF) Need a new table since State is determined by ______________ What is the PK? ______________ 2NF 3NF

10 10 Employee Data EmpNoNameDeptSalaryCourse Date Completed Dept Phone Ext. 100JohnMKTG42000SPSS6/19/20135325 Surveys11/3/20145325 140SueACCT41000Tax Acc12/1/20144422 110BobINFO70000Java3/21/20137373 C#10/23/20157373 190AlexFINA65000Investmts.2/1/20134477 150JenniferINFO49000Java3/11/20127373 Oracle5/19/20137373 Courses Taken Listing Notice in this report that Employees can take multiple courses.

11  No repeating fields or groups! Note: notice the Primary Key! 11 First Normal Form(1NF) EmpNoNameDeptSalaryCourseDate Completed Dept Phone Ext. 100JohnMKTG42000SPSS6/19/20135325 100JohnMKTG42000Surveys11/3/20145325 140SueACCT41000Tax Acc12/1/20144422 110BobINFO70000Java3/21/20137373 110BobINFO70000C#10/23/20157373 190AlexFINA65000Investmts.2/1/20134477 150JenniferINFO49000Java3/11/20127373 150JenniferINFO49000Oracle5/19/20137373 EmpCourse(EmpNo, Name, Dept, Salary, Course, Date Completed, DeptPhoneExt) EmpCourse

12  Ensure that all non-key attributes are functionally dependent on the entire primary key! 12 Let’s transform this table from 1NF to 2NF EmpCourse(EmpNo, Name, Dept, Salary, Course, Date Completed, DeptPhoneExt) EmpNo, Course  EmpNo  Course  EmpNoNameDeptSalaryCourseDate Completed Dept Phone Ext. 100JohnMKTG42000SPSS6/19/20135325 100JohnMKTG42000Surveys11/3/20145325 140SueACCT41000Tax Acc12/1/20144422 110BobINFO70000Java3/21/20137373 110BobINFO70000C#10/23/20157373 190AlexFINA65000Investmts.2/1/20134477 150JenniferINFO49000Java3/11/20127373 150JenniferINFO49000Oracle5/19/20137373 EmpCourse

13  NOW, all non-key attributes are functionally dependent on the entire primary key! 13 2NF EmpNoNameDeptSalaryDept Phone Ext. 100JohnMKTG420005325 140SueACCT410004422 110BobINFO700007373 190AlexFINA650004477 150JenniferINFO490007373 Employee (EmpNo, Name, Dept, Salary, DeptPhoneExt) EmpNoCourseDate Completed 100SPSS6/19/2013 100Surveys11/3/2014 140Tax Acc12/1/2014 110Java3/21/2013 110C#10/23/2015 190Investmts.2/1/2013 150Java3/11/2012 150Oracle5/19/2013 EmpCourse( EmpNo, Course, Date Completed EmployeeEmpCourse

14  Ensure that all non-primary key attributes do not depend on each other (i.e. no transitive dependencies). 14 Not in 3NF __________  DeptPhoneExt EmpNoNameDeptSalaryDept Phone Ext. 100JohnMKTG420005325 140SueACCT410004422 110BobINFO700007373 190AlexFINA650004477 150JenniferINFO490007373 EmpNoCourseDate Completed 100SPSS6/19/2013 100Surveys11/3/2014 140Tax Acc12/1/2014 110Java3/21/2013 110C#10/23/2015 190Investmts.2/1/2013 150Java3/11/2012 150Oracle5/19/2013 Do any of the non-key attributes (Name, Dept, or Salary) determine the phone number? This one is already in 3NF since it has only has one non-key attribute! EmployeeEmpCourse

15  NOW, all non-primary key attributes do not depend on each other 15 3NF EmpCourse(EmpNo, Course, Date Completed DeptDept Phone Ext. MKTG5325 ACCT4422 INFO7373 FINA4477 Department(Dept, DeptPhoneExt) EmpNoNameDeptSalary 100JohnMKTG42000 140SueACCT41000 110BobINFO70000 190AlexFINA65000 150JenniferINFO49000 EmpNoCourseDate Completed 100SPSS6/19/2013 100Surveys11/3/2014 140Tax Acc12/1/2014 110Java3/21/2013 110C#10/23/2015 190Investmts.2/1/2013 150Java3/11/2012 150Oracle5/19/2013 Employee(EmpNo, Name, Dept, Salary) EmployeeEmpCourseDept

16  that to represent the data on this report in a relational database, we will need to create 3 separate tables. 16 Using Normalization we learned… EmpNoNameDeptSalary 100JohnMKTG42000 140SueACCT41000 110BobINFO70000 190AlexFINA65000 150JenniferINFO49000 EmpNoCourseDate Completed 100SPSS6/19/2013 100Surveys11/3/2014 140Tax Acc12/1/2014 110Java3/21/2013 110C#10/23/2015 190Investmts.2/1/2013 150Java3/11/2012 150Oracle5/19/2013 DeptDept Phone Ext. MKTG5325 ACCT4422 INFO7373 FINA4477 Employee EmpCourse Dept 

17 17 Here's our solution! Employee EmpNo - PK Name DeptCode Salary EmpNo - PK Name DeptCode Salary Dept DeptCode - PK DeptPhoneExt DeptCode - PK DeptPhoneExt EmpCourse EmpNo Course DateCompleted EmpNo Course DateCompleted PK 0..* 1..1 1..* What are the foreign keys?

18 Integrity Controls  Input Controls prevent erroneous data − Value limit controls − Completeness controls − Data validation controls − Field combination controls  Output Controls accurate, current, and complete − Physical access to output devices − Discarded output − Completeness pg 1 of 10 − Currency date & timestamp 18

19 Integrity Controls  Access Controls SIUD; Views  Complex update controls Handling multi-user updates – DBMS handles  Protection from hardware failures Backup & Recovery Redundancy  Transaction Logging 2 benefits 19

20 Integrity Controls  Fraud Prevention Fraud Triangle  Techniques to  risk Separation of duties Records & Audit trails Monitoring − Unusual transactions Asset control − Limit physical access Security 20

21 21 Normalization Practice Order No Cust No NameAddrCityStZipOrder Date Promised Date Prod No DescQty Ord Unit Price 613841273 Cont. Designs 123 OakAustinTX 2838411/04/1311/21/13 M128 Bookcase 4200 613841273 Cont. Designs 123 OakAustinTX 2838411/04/1311/21/13 B381 Cabinet 2150 613841273 Cont. Designs 123 OakAustinTX 2838411/04/1311/21/13 R210 Table 1500 628903891 J Consultants 523 PineWacoTX 7671211/15/1311/21/13 A891 Chair 2300 628903891 J Consultants 523 PineWacoTX 7671211/15/1311/21/13 M128 Bookcase 8200 631291273 Cont. Designs 123 OakAustinTX 2838412/10/1312/29/13 A891 Chair 6300  It’s already in 1NF …but you need to understand why!  Convert this to 2NF. How many tables do you now have?  Convert this to 3NF. How many tables do you now have?

22 22 Normalization Practice Appointment Table Appt No Appt Date Appt Time Planned Duration Appt Type Patient ID First Nm Last NmPhone Doctor ID Doctor Nm 112/1/20153:00 AM1.00Physical466927LisaGarcia562-3456C678Chapman 212/1/20153:00 AM0.25Shot456789SueCarey432-1234A528Lopez 312/1/20153:15 AM0.50Flu194756BrandonPierre432-7877S626Smith 412/2/201510:00 AM0.50Migraine329657MarcusSchwartz239-5502A528Lopez 512/2/201510:15 AM0.25Shot987453MikeJones456-0202G123Gray 612/2/201510:30 AM0.25Shot384788TonyaJohnson432-8806S626Smith 712/2/201510:45 AM0.50Flu438754IlianaHnatt823-4303C678Chapman 812/2/201511:00 AM1.00Physical345875CarlaBasich857-5566A528Lopez 912/3/201510:30 AM1.00Physical466927LisaGarcia562-3456C678Chapman 1012/3/20159:00 AM0.50Migraine345875CarlaBasich857-5666C678Chapman  It’s already in 1NF, and 2NF …but you need to understand why!  Convert this to 3NF. How many tables do you now have?


Download ppt "Database Design Chapter 9 Part-2: Normalization 1."

Similar presentations


Ads by Google