+ All Categories
Home > Documents > Database Design Chapter 9 Part-2: Normalization 1.

Database Design Chapter 9 Part-2: Normalization 1.

Date post: 18-Jan-2018
Category:
Upload: antony-copeland
View: 225 times
Download: 0 times
Share this document with a friend
Description:
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: 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.00Physical466927LisaGarcia C678Chapman 212/1/20153:00 AM0.25Shot456789SueCarey A528Lopez 312/1/20153:15 AM0.50Flu194756BrandonPierre S626Smith 412/2/201510:00 AM0.50Migraine329657MarcusSchwartz A528Lopez 512/2/201510:15 AM0.25Shot987453MikeJones G123Gray 612/2/201510:30 AM0.25Shot384788TonyaJohnson S626Smith 712/2/201510:45 AM0.50Flu438754IlianaHnatt C678Chapman 812/2/201511:00 AM1.00Physical345875CarlaBasich A528Lopez 912/3/201510:30 AM1.00Physical466927LisaGarcia C678Chapman 1012/3/20159:00 AM0.50Migraine345875CarlaBasich C678Chapman 12/2/2015
22
Database Design Chapter 9 Part-2: Normalization 1
Transcript
Page 1: Database Design Chapter 9 Part-2: Normalization 1.

1

Database Design

Chapter 9Part-2: Normalization

Page 2: Database Design Chapter 9 Part-2: Normalization 1.

2

Part TwoNormalization −1NF−2NF−3NF

Integrity Controls

Outline

Page 3: Database Design Chapter 9 Part-2: Normalization 1.

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

Page 4: Database Design Chapter 9 Part-2: Normalization 1.

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.

Page 5: Database Design Chapter 9 Part-2: Normalization 1.

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

Page 6: Database Design Chapter 9 Part-2: Normalization 1.

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)

Page 7: Database Design Chapter 9 Part-2: Normalization 1.

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

Page 8: Database Design Chapter 9 Part-2: Normalization 1.

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

Page 9: Database Design Chapter 9 Part-2: Normalization 1.

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

Page 10: Database Design Chapter 9 Part-2: Normalization 1.

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.

Page 11: Database Design Chapter 9 Part-2: Normalization 1.

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

Page 12: Database Design Chapter 9 Part-2: Normalization 1.

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

Page 13: Database Design Chapter 9 Part-2: Normalization 1.

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

Page 14: Database Design Chapter 9 Part-2: Normalization 1.

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

Page 15: Database Design Chapter 9 Part-2: Normalization 1.

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

Page 16: Database Design Chapter 9 Part-2: Normalization 1.

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

Page 17: Database Design Chapter 9 Part-2: Normalization 1.

17

Here's our solution!

EmployeeEmpNo - PKNameDeptCodeSalary

DeptDeptCode - PKDeptPhoneExt

EmpCourseEmpNoCourseDateCompleted

PK

0..*

1..1

1..1

1..*

What are the foreign keys?

Page 18: Database Design Chapter 9 Part-2: Normalization 1.

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

Page 19: Database Design Chapter 9 Part-2: Normalization 1.

19

Integrity ControlsAccess Controls

SIUD; Views

Complex update controlsHandling multi-user updates – DBMS handles

Protection from hardware failuresBackup & RecoveryRedundancy

Transaction Logging2 benefits

Page 20: Database Design Chapter 9 Part-2: Normalization 1.

20

Integrity ControlsFraud Prevention

Fraud Triangle

Techniques to riskSeparation of dutiesRecords & Audit trailsMonitoring−Unusual transactions

Asset control− Limit physical access

Security

Page 21: Database Design Chapter 9 Part-2: Normalization 1.

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?

Page 22: Database Design Chapter 9 Part-2: Normalization 1.

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?


Recommended