Top Banner
Concepts of Database Management Seventh Edition Chapter 5 Database Design 1: Normalization
54

Concepts of Database Management Seventh Edition

Feb 25, 2016

Download

Documents

honey

Concepts of Database Management Seventh Edition. Chapter 5 Database Design 1: Normalization. Objectives. Discuss functional dependence and primary keys Define first normal form, second normal form, and fourth normal form - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Concepts of Database Management Seventh Edition

Concepts of Database ManagementSeventh Edition

Chapter 5Database Design 1: Normalization

Page 2: Concepts of Database Management Seventh Edition

Objectives

• Discuss functional dependence and primary keys• Define first normal form, second normal form, and

fourth normal form• Describe the problems associated with tables

(relations) that are not in first normal form, second normal form, or third normal form, along with the mechanism for converting to all three

• Understand how normalization is used in the database design process

2

Page 3: Concepts of Database Management Seventh Edition

Introduction

• Normalization process– Identifying potential problems, called update

anomalies, in the design of a relational database– Methods for correcting these problems

• Normal form: table has desirable properties– First normal form (1NF)– Second normal form (2NF)– Third normal form (3NF)

3

Page 4: Concepts of Database Management Seventh Edition

Introduction (continued)

• Normalization – Table in first normal form better than table not in first

normal form– Table in second normal form better than table in first

normal form, and so on– Goal: new collection of tables that is free of update

anomalies

4

Page 5: Concepts of Database Management Seventh Edition

Functional Dependence

5

BAA certain field say Column B is functionally dependent

on another field say Column A if Column B’s value dependon the value of Column A. And also that Column A’s value is associated only with a exactly one value of Column B.

And so if Column B depends on Column A then it also means that Column A functionally determines Column B.

Page 6: Concepts of Database Management Seventh Edition

Functional Dependence (continued)

FIGURE 5-2: Rep table with additional column, PayClass

6

Let’s assume that in Premiere Products all Sales Rep in any givenPay class earn the Commission Rate.

So, which means

And his/her Commission Rate

a Sale’s Rep Pay Class his/her Commission Ratedetermines

therefore depends on his/her Pay Class

PayClass Rate

Page 7: Concepts of Database Management Seventh Edition

Functional Dependence (continued)

7

Let’s make it a local example here. Suppose we have a Courses table below:

That is, Course Code determines his/her Course Description

And Course Description depends on Course Code

Course Code Course DescriptionIS230 Database Design

CA100 Computer Literacy

BU101 Intro to Business

Course Code Course Description

Page 8: Concepts of Database Management Seventh Edition

Functional Dependence (continued)

8

Given a Salary table for Faculties of a community college which one field determines which field and which field depends which field?

Position Annual SalaryInstructor 16,000

Assistant Professor 19,000

Associate Professor 24,000

Professor 29,000

Professor Emeritus 35,000

Page 9: Concepts of Database Management Seventh Edition

Let us examine Rep table on Premier Database

FIGURE 5-4: Rep table with second rep named Kaiser added

FIGURE 5-3: Rep table

9

Page 10: Concepts of Database Management Seventh Edition

Question?

Is Street functionally depend on Firstname or Lastname?

10

Page 11: Concepts of Database Management Seventh Edition

Question?

Is CustomerName Functionally Dependent on RepNum?

FIGURE 5-3: Rep table

11

Page 12: Concepts of Database Management Seventh Edition

Question?

So, on which columns does QuotedPrice is functionally dependent?

12

Is QuotedPrice Functionally Dependent on PartNum?

Is QuotedPrice Functionally Dependent on OrderNum?

Page 13: Concepts of Database Management Seventh Edition

Non-Graded Exercise

13

Identify which field(s) is functionally dependent on which field(s)And then which field(s) functionally determines which field(s).

StudID

StudeLast StudFirst HighSchoolNum

HighSchoolName

AdvisorNum

AdvisorName

1 Cruz John 101 CCA 990 Smith

2 Moore Anna 102 SDA 991 Song

3 Friend Fe 101 CCA 991 Song

4 Zap Mario 103 MNHS 990 Smith

5 Bass Gerard 103 MNHS 992 George

Page 14: Concepts of Database Management Seventh Edition

Primary Key and Functional Depedence

14

• Remember the primary key concept that we learn on Chapter 4?

• Primary key uniquely identifies a record or row.• The key in determining if column is functionally

dependent to another column is to ask the question, is a certain column functionally dependent to the Primary Key.

Page 15: Concepts of Database Management Seventh Edition

Primary Key and Functional Depedence

15

What is the Primary Key of Part table?

Is Warehouse functionally dependent on Class?

Is the Combination of Partnum and Descriptin is the Primary Key?

Page 16: Concepts of Database Management Seventh Edition

Primary Key and Functional Depedence

16

Is CustomerNum the Primary Key for Customer table?

Does CustomerNum determines the values of the other fields?

Page 17: Concepts of Database Management Seventh Edition

Question?

Is OrderNum the Primary Key of OrderLine table?

FIGURE 5-3: Rep table

17

What is the Primary Key of OrderLine Table?

Page 18: Concepts of Database Management Seventh Edition

Nothing but the Key

18

• The key thought in normalization is the primary key.

• To Quote E.F. Codd the father of relational database systems.– “[Every] non-key [attribute] must provide a fact

about the key, the whole key, and nothing but the key.”

• Take this into mind as we go on three basic normal forms in Database Design.

Page 19: Concepts of Database Management Seventh Edition

Three Normal Forms Mnemonics

• In order to easily remember the three normal forms just remember the word RePeaT ignoring the vowels (which are in small letters) which are:

19

R – 1ST Normal Form - No Repeating groups or multi-valued fields

T – 3rd Normal Form - No Transitional Dependence

P – 2nd Normal Form - No Partial Dependence

Page 20: Concepts of Database Management Seventh Edition

First Normal Form

• There should be no repeating group or multi-valued columns in order for a Table to be in first normal form.– Repeating group: multiple entries for a single

record– Unnormalized relation: contains a repeating group

20

Page 21: Concepts of Database Management Seventh Edition

First Normal Form (continued)

Orders (OrderNum, OrderDate, (PartNum, NumOrdered) )

FIGURE 5-5: Sample unnormalized table

21

Repeating Group or Multi-valued Columns

Repeating Group or Multi-valued Columns

Page 22: Concepts of Database Management Seventh Edition

First Normal Form (continued)

Orders (OrderNum, OrderDate, PartNum, NumOrdered)

FIGURE 5-6: Result of normalization (conversion to first normal form)

22

Converted toFirst Normal Form

No more Multi-valuedfields

Page 23: Concepts of Database Management Seventh Edition

Second Normal Form (continued)

• Table (relation) in second normal form (2NF)– Table is in first normal form– No nonkey column (not a primary key) column

should be partially dependent of a composite primary key.

• Partial dependencies: only on a portion of the primary key

23

Page 24: Concepts of Database Management Seventh Edition

Second Normal Form

24

Description is partially dependent on PartNum but not on both OrderNum and PartNum which are the composite Primary Key.

Primary Key : OrderNum and PartNum

OrderDate is partially dependent on OrderNum but not on both OrderNum and PartNum which is the composite Primary Key.

Page 25: Concepts of Database Management Seventh Edition

Converting to Second Normal Form

25

OrderNum OrderDateXBecause the Primary Key is OrderNum and Partnum

Page 26: Concepts of Database Management Seventh Edition

Converting to Second Normal Form

26

XRemove partially dependent field OrderDate

And make a new table out of it let’s say in this case Orders table

Page 27: Concepts of Database Management Seventh Edition

Converting to Second Normal Form

27

PartNum DescriptionXBecause the Primary Key is OrderNum and Partnum

Page 28: Concepts of Database Management Seventh Edition

Converting to Second Normal Form

28

X

Remove partially dependent field Description

And make a new table out of it let’s say in this case Part table

Page 29: Concepts of Database Management Seventh Edition

Converting to Second Normal Form

29

XX

The Original table becomes a new table which is Normalized. And let’s say we name it OderLine table.

Page 30: Concepts of Database Management Seventh Edition

Second Normal Form (continued)

FIGURE 5-9: Conversion to second normal form30

Page 31: Concepts of Database Management Seventh Edition

Third Normal Form (continued)

• Table (relation) in third normal form (3NF)– It is in second normal form– There should no non-primary key that is transitional

dependent to a primary key.

31

Page 32: Concepts of Database Management Seventh Edition

Third Normal Form (continued)

FIGURE 5-10: Sample Customer table

32

Page 33: Concepts of Database Management Seventh Edition

Third Normal Form

• Customer (CustomerNum, CustomerName, Balance, CreditLimit, RepNum, LastName, FirstName)

• Functional dependencies:– CustomerNum → CustomerName, Balance,

CreditLimit, RepNum, LastName, FirstName– RepNum → LastName, FirstName

33

Page 34: Concepts of Database Management Seventh Edition

Third Normal Form (continued)

• Correction procedure– Remove each column that is transitionally

dependent.– Create a new table, transferring the removed

columns to the newly created table.– Make a primary key of the new table– And use the primary key as the foreign key from the

table where the columns were removed earlier.

34

Page 35: Concepts of Database Management Seventh Edition

Third Normal Form (continued)

35FIGURE 5-12: Conversion to third normal form

Page 36: Concepts of Database Management Seventh Edition

Third Normal Form (continued)

FIGURE 5-12: Conversion to third normal form (continued)

36

Page 37: Concepts of Database Management Seventh Edition

Incorrect Decompositions

• Decomposition must be done using method described for 3NF

• Incorrect decompositions can lead to tables with the same problems as original table

37

Page 38: Concepts of Database Management Seventh Edition

Incorrect Decompositions (continued)

FIGURE 5-13: Incorrect decomposition of the Customer table

38

Page 39: Concepts of Database Management Seventh Edition

Incorrect Decompositions (continued)

FIGURE 5-13: Incorrect decomposition of the Customer table (continued)

39

Page 40: Concepts of Database Management Seventh Edition

Incorrect Decompositions (continued)

FIGURE 5-14: Second incorrect decomposition of the Customer table

40

Page 41: Concepts of Database Management Seventh Edition

Incorrect Decompositions (continued)

FIGURE 5-14: Second incorrect decomposition of the Customer table (continued)

41

Page 42: Concepts of Database Management Seventh Edition

Guess which normal form it violates?

42

EmployeeID Lastname Firstname Gender Computer Skills

1 James George M Encoding, MS Office, Photoshop

2 Miles May F Encoding, Programming, Database Design

3 Gates Alan M Programming, MS Office

How should we normalized the above table?

Let’s say we want to store Employee’s different computer skills on a table.

Page 43: Concepts of Database Management Seventh Edition

Guess which normal form it violates?

43

CustomerID Lastname Firstname ContactNumber1 Christopher Rey 320-1871, 320-

1584

2 Allen George 320-1264

3 Green Rhea 320-1987, 320-1574,320-9874

How should we normalized the above table?

Let’s say we want to store Customer’s contact numbers.

Page 44: Concepts of Database Management Seventh Edition

Guess which normal form it violates?

44

StudentID CourseCode

Lastname Firstname CourseDescription

Section

1001 IS230 Mills Karen Database Design

1

1002 CA100 Courtney Francis Computer Literacy

2

1003 EN110 Smith Phillip Advanced Reading

5

1002 EN110 Courtney Francis Advanced Reading

3

1004 CA100 Morrison John Computer Literacy

2

How should we normalized the above table?

Let’s say we want to store Students who takes courses on a particular section.

Page 45: Concepts of Database Management Seventh Edition

Guess which normal form it violates?

45

SemesterCode

SemesterYear

SemsterSeason

StudentID Lastname Firstname

2012-1 2012 Spring 1001 Mills Karen

2012-1 2012 Spring 1002 Courtney Francis

2012-3 2012 Fall 1003 Smith Phillip

2012-3 2012 Fall 1004 Morrison John

2012-3 2012 Fall 1005 Dylan Sarah

How should we normalized the above table?

Let’s say we want a table that stores those who enroll in a certain semester.

Page 46: Concepts of Database Management Seventh Edition

Guess which normal form it violates?

46

CourseCode Section FacultyID Lastname FirstnameIS230 1 2001 Castro Edper

CA100 4 2010 Mangonon George

EN110 1 3015 Rivera Monica

SS150 2 1501 Haglelgam John

MS100 1 3651 Verg-in Yenti

How should we normalized the above table?

Let’s say we want a table that stores the courses that Faculty taught.

Page 47: Concepts of Database Management Seventh Edition

Guess which normal form it violates?

47

DivisionID DivisionName FacultyID Lastname Firstname1 Business 1010 Felix, Jr. Joseph

2 Education 1008 Hallers Maggie

3 HCOP 4025 Dacanay Paul

4 Math and Science 2641 Biza Snyther

How should we normalized the above table?

Let’s say we want a table that stores who is the division chair of a certain division.

Page 48: Concepts of Database Management Seventh Edition

Graded Case Study – Alexamara

48

Problem 1 : Normalize the table below

OwnerNum LastName FirstName BoatName Weight Marina

AD57 Adney Bruce and Jean AdBruce X 1,000 lbs East

Zinger 1,500 lbs East

AN75 Anderson Bill Yellow Beast 2,000 lbs West

BL72 Blake Mary Kumodo 1,200 lbs East

Kryptonite 1,000 lbs West

EL25 Elend Sandy and Bill Shark Fin 1,300 lbs East

Two Cute 900 lbs East

Ride North 1,400 lbs West

Page 49: Concepts of Database Management Seventh Edition

Graded Case Study - Alexamara

49

Problem 2 : Normalize the table below

SlipID MarinaNum SlipNum Length RentalFee BoatName BoatType OwnerNum OwnerLastName OwnerFirstName

1 1 A1 40 $3,800.00 Anderson II Sprite 4000 AN75 Anderson Bill

2 1 A2 40 $3,800.00 Our Toy Ray 4025 EL25 Elend Sand and Bill

3 1 A3 40 $3,600.00 Escape Sprite 4000 KE22 Kelly Allysa

4 1 B1 30 $2,400.00 Gypsy Dolphin 28 JU92 Juarez Maria

5 1 B2 30 $2,600.00 Anderson III Sprite 3000 AN75 Anderson Bill

6 2 1 25 $1,800.00 Bravo Dolphin 25 AD57 Adney Bruce and Jean

7 2 2 25 $1,800.00 Chinook Dolphin 22 FE82 Feenstra Daniel

8 2 3 25 $2,000.00 Listy Dolphin 25 SM72 Smeltz Beck and Dave

9 2 4 30 $2,500.00 Mermaid Dolphin 28 BL72 Blake Mary

10 2 5 40 $4,200.00 Axxon II Dolphin 40 NO27 Norton Peter

11 2 6 40 $4,200.00 Karvel Ray 4025 TR72 Trent Ashton

Page 50: Concepts of Database Management Seventh Edition

Graded Case Study – Henry Books

50

Problem 1 : Normalize the table below

PublisherCode PublisherName City BookTitle YearPublished

AH Arkham House Sauk City WI Dream House 1999

Partial Recall 2011

AP Arcade Publishing New York Games Played 1982

BA Basic Books Boulder CO Dance Fundamentals 1980

Booking the Flight 1993

BP Berkley Publishing Boston Bastketball glory 2001

VB Vintage Books New York Archive Reload 1998

Rusty Road 2002

WN W.W. Norton New York War and Breeze 2006

WP Westview Press Boulder CO General Goodwill 1978

Page 51: Concepts of Database Management Seventh Edition

Graded Case Study – Henry Books

51

Problem 2 : Normalize the table below

BookCode Title AuthorCode AuthorFirstname AuthorLastname

0180 A Deepness in the Sky 1001 George Graham

0189 Magic Terror 1002 Earl Johnson

0200 The Stranger 1001 George Graham

0378 Venice 1003 Vitali Pablo

079X Second Wind 1004 Strong Mary

0808 The Edge 1002 Earl Johnson

Page 52: Concepts of Database Management Seventh Edition

Summary

• Column (attribute) B is functionally dependent on another column A (or collection of columns) when each value for A in the database is associated with exactly one value of B

• Column(s) A is the primary key if all other columns are functionally dependent on A and no sub-collection of columns in A also have this property

52

Page 53: Concepts of Database Management Seventh Edition

Summary (continued)

• Table (relation) in first normal form (1NF) does not contain repeating groups

• Nonkey column (or nonkey attribute) is not a part of the primary key

• Table (relation) is in the second normal form (2NF) when it is in 1NF and no nonkey column is dependent on only a portion of the primary key

• Determinant is a column that functionally determines another column

53

Page 54: Concepts of Database Management Seventh Edition

Summary (continued)

• Table (relation) is in third normal form (3NF) when it is in 2NF and its only determinants are candidate keys

• Collection of tables (relations) that is not in third normal form has inherent problems called update anomalies

54