Date post: | 18-Jan-2018 |
Category: |
Documents |
Upload: | antony-copeland |
View: | 225 times |
Download: | 0 times |
1
Database Design
Chapter 9Part-2: Normalization
2
Part TwoNormalization −1NF−2NF−3NF
Integrity Controls
Outline
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 15th.
Insert Anomaly
ApptNo
ApptDate
ApptTime
PlannedDuration
ApptType
PatientID
FirstNm
LastNm Phone
DoctorID
DoctorNm
1 12/1/2015 3:00 AM 1.00 Physical 466927 Lisa Garcia 562-3456 C678 Chapman2 12/1/2015 3:00 AM 0.25 Shot 456789 Sue Carey 432-1234 A528 Lopez3 12/1/2015 3:15 AM 0.50 Flu 194756 Brandon Pierre 432-7877 S626 Smith4 12/2/2015 10:00 AM 0.50 Migraine 329657 Marcus Schwartz 239-5502 A528 Lopez5 12/2/2015 10:15 AM 0.25 Shot 987453 Mike Jones 456-0202 G123 Gray6 12/2/2015 10:30 AM 0.25 Shot 384788 Tonya Johnson 432-8806 S626 Smith7 12/2/2015 10:45 AM 0.50 Flu 438754 Iliana Hnatt 823-4303 C678 Chapman8 12/2/2015 11:00 AM 1.00 Physical 345875 Carla Basich 857-5566 A528 Lopez9 12/3/2015 10:30 AM 1.00 Physical 466927 Lisa Garcia 562-3456 C678 Chapman
10 12/3/2015 9:00 AM 0.50 Migraine 345875 Carla Basich 857-5566 C678 Chapman
12/2/2015
4
(def) the process of converting complex data structures into simple, stable data structures.
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.
Normalization
NormalizationNormal
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)
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!
Functional Dependency
Field A is functionally dependent on Field Bif 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
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
Third Normal Form (3NF)
Need a new table since State
is determined by ______________
What is the PK?
______________
2NF
3NF
10
Employee Data
EmpNo Name Dept Salary CourseDate
CompletedDept
Phone Ext.100 John MKTG 42000 SPSS 6/19/2013 5325
Surveys 11/3/2014 5325
140 Sue ACCT 41000 Tax Acc 12/1/2014 4422
110 Bob INFO 70000 Java 3/21/2013 7373
C# 10/23/2015 7373
190 Alex FINA 65000 Investmts. 2/1/2013 4477
150 Jennifer INFO 49000 Java 3/11/2012 7373
Oracle 5/19/2013 7373
Courses Taken Listing
Notice in this report that Employees can take multiple courses.
11
No repeating fields or groups!Note: notice the Primary Key!
First Normal Form(1NF)
EmpNo Name Dept Salary Course Date Completed
DeptPhone Ext.
100 John MKTG 42000 SPSS 6/19/2013 5325100 John MKTG 42000 Surveys 11/3/2014 5325
140 Sue ACCT 41000 Tax Acc 12/1/2014 4422110 Bob INFO 70000 Java 3/21/2013 7373110 Bob INFO 70000 C# 10/23/2015 7373190 Alex FINA 65000 Investmts. 2/1/2013 4477
150 Jennifer INFO 49000 Java 3/11/2012 7373150 Jennifer INFO 49000 Oracle 5/19/2013 7373
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!
Let’s transform this tablefrom 1NF to 2NF
EmpCourse(EmpNo, Name, Dept, Salary, Course, Date Completed, DeptPhoneExt)
EmpNo, Course
EmpNo
Course
EmpNo Name Dept Salary Course Date Completed
DeptPhone Ext.
100 John MKTG 42000 SPSS 6/19/2013 5325
100 John MKTG 42000 Surveys 11/3/2014 5325
140 Sue ACCT 41000 Tax Acc 12/1/2014 4422
110 Bob INFO 70000 Java 3/21/2013 7373
110 Bob INFO 70000 C# 10/23/2015 7373
190 Alex FINA 65000 Investmts. 2/1/2013 4477
150 Jennifer INFO 49000 Java 3/11/2012 7373
150 Jennifer INFO 49000 Oracle 5/19/2013 7373
EmpCourse
13
NOW, all non-key attributes are functionally dependent on the entire primary key!
2NF
EmpNo Name Dept Salary DeptPhone Ext.
100 John MKTG 42000 5325
140 Sue ACCT 41000 4422110 Bob INFO 70000 7373190 Alex FINA 65000 4477
150 Jennifer INFO 49000 7373
Employee (EmpNo, Name, Dept, Salary, DeptPhoneExt)
EmpNo Course Date Completed
100 SPSS 6/19/2013
100 Surveys 11/3/2014
140 Tax Acc 12/1/2014
110 Java 3/21/2013
110 C# 10/23/2015
190 Investmts. 2/1/2013
150 Java 3/11/2012
150 Oracle 5/19/2013
EmpCourse( EmpNo, Course, Date Completed
Employee EmpCourse
14
Ensure that all non-primary key attributes do not depend on each other (i.e. no transitive dependencies).
Not in 3NF
__________ DeptPhoneExt
EmpNo Name Dept Salary DeptPhone Ext.
100 John MKTG 42000 5325
140 Sue ACCT 41000 4422
110 Bob INFO 70000 7373
190 Alex FINA 65000 4477
150 Jennifer INFO 49000 7373
EmpNo Course Date Completed
100 SPSS 6/19/2013
100 Surveys 11/3/2014
140 Tax Acc 12/1/2014
110 Java 3/21/2013
110 C# 10/23/2015
190 Investmts. 2/1/2013
150 Java 3/11/2012
150 Oracle 5/19/2013
Do any of the non-key attributes (Name, Dept, or Salary)
determine the phone number?
This one is already in 3NF since ithas only has one non-key attribute!
Employee EmpCourse
15
NOW, all non-primary key attributes do not depend on each other
3NF
EmpCourse(EmpNo, Course, Date Completed
Dept DeptPhone Ext.
MKTG 5325
ACCT 4422
INFO 7373
FINA 4477
Department(Dept, DeptPhoneExt)
EmpNo Name Dept Salary
100 John MKTG 42000
140 Sue ACCT 41000
110 Bob INFO 70000
190 Alex FINA 65000
150 Jennifer INFO 49000
EmpNo Course Date Completed
100 SPSS 6/19/2013
100 Surveys 11/3/2014
140 Tax Acc 12/1/2014
110 Java 3/21/2013
110 C# 10/23/2015
190 Investmts. 2/1/2013
150 Java 3/11/2012
150 Oracle 5/19/2013
Employee(EmpNo, Name, Dept, Salary)
Employee EmpCourse Dept
16
that to represent the data on this report in a relational database, we will need to create 3 separate tables.
Using Normalization we learned…
EmpNo Name Dept Salary
100 John MKTG 42000
140 Sue ACCT 41000
110 Bob INFO 70000
190 Alex FINA 65000
150 Jennifer INFO 49000EmpNo Course Date Completed
100 SPSS 6/19/2013
100 Surveys 11/3/2014
140 Tax Acc 12/1/2014
110 Java 3/21/2013
110 C# 10/23/2015
190 Investmts. 2/1/2013
150 Java 3/11/2012
150 Oracle 5/19/2013
Dept DeptPhone Ext.
MKTG 5325
ACCT 4422
INFO 7373
FINA 4477
Employee
EmpCourse
Dept
17
Here's our solution!
EmployeeEmpNo - PKNameDeptCodeSalary
DeptDeptCode - PKDeptPhoneExt
EmpCourseEmpNoCourseDateCompleted
PK
0..*
1..1
1..1
1..*
What are the foreign keys?
18
Integrity ControlsInput Controls
prevent erroneous data −Value limit controls−Completeness controls−Data validation controls−Field combination controls
Output Controlsaccurate, current, and
complete−Physical access to output
devices−Discarded output−Completeness• pg 1 of 10
−Currency• date & timestamp
19
Integrity ControlsAccess Controls
SIUD; Views
Complex update controlsHandling multi-user updates – DBMS handles
Protection from hardware failuresBackup & RecoveryRedundancy
Transaction Logging2 benefits
20
Integrity ControlsFraud Prevention
Fraud Triangle
Techniques to riskSeparation of dutiesRecords & Audit trailsMonitoring−Unusual transactions
Asset control− Limit physical access
Security
21
Normalization PracticeOrder
NoCustNo
Name Addr City St Zip OrderDate
PromisedDate
ProdNo
Desc QtyOrd
UnitPrice
61384 1273 Cont. Designs 123 Oak Austin TX 28384 11/04/13 11/21/13 M128 Bookcase 4 200
61384 1273 Cont. Designs 123 Oak Austin TX 28384 11/04/13 11/21/13 B381 Cabinet 2 15061384 1273 Cont. Designs 123 Oak Austin TX 28384 11/04/13 11/21/13 R210 Table 1 50062890 3891 J Consultants 523 Pine Waco TX 76712 11/15/13 11/21/13 A891 Chair 2 30062890 3891 J Consultants 523 Pine Waco TX 76712 11/15/13 11/21/13 M128 Bookcase 8 20063129 1273 Cont. Designs 123 Oak Austin TX 28384 12/10/13 12/29/13 A891 Chair 6 300
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
Normalization PracticeAppointment Table
ApptNo
ApptDate
ApptTime
PlannedDuration
ApptType
PatientID
FirstNm
LastNm Phone
DoctorID
DoctorNm
1 12/1/2015 3:00 AM 1.00 Physical 466927 Lisa Garcia 562-3456 C678 Chapman2 12/1/2015 3:00 AM 0.25 Shot 456789 Sue Carey 432-1234 A528 Lopez3 12/1/2015 3:15 AM 0.50 Flu 194756 Brandon Pierre 432-7877 S626 Smith4 12/2/2015 10:00 AM 0.50 Migraine 329657 Marcus Schwartz 239-5502 A528 Lopez5 12/2/2015 10:15 AM 0.25 Shot 987453 Mike Jones 456-0202 G123 Gray6 12/2/2015 10:30 AM 0.25 Shot 384788 Tonya Johnson 432-8806 S626 Smith7 12/2/2015 10:45 AM 0.50 Flu 438754 Iliana Hnatt 823-4303 C678 Chapman8 12/2/2015 11:00 AM 1.00 Physical 345875 Carla Basich 857-5566 A528 Lopez9 12/3/2015 10:30 AM 1.00 Physical 466927 Lisa Garcia 562-3456 C678 Chapman
10 12/3/2015 9:00 AM 0.50 Migraine 345875 Carla Basich 857-5666 C678 Chapman
It’s already in 1NF, and 2NF …but you need to understand why! Convert this to 3NF. How many tables do you now have?