30
Concepts of Database Concepts of Database Management, Fifth Management, Fifth Edition Edition Chapter 5: Chapter 5: Database Design 1: Database Design 1: Normalization Normalization

Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

Embed Size (px)

Citation preview

Page 1: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

Concepts of Database Concepts of Database Management, Fifth Management, Fifth

EditionEdition

Chapter 5: Chapter 5:

Database Design 1:Database Design 1:

NormalizationNormalization

Page 2: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

2

5

Concepts of Database Management

Objectives

Discuss functional dependence

Discuss primary keys

Define first normal form, second normal form, and third 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

Page 3: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

3

5

Concepts of Database Management

Objectives

Discuss the problems associated with incorrect conversions to third normal form

Define fourth normal form

Describe the problems associated with tables (relations) that are not in fourth normal form and describe the mechanism for converting to fourth normal form

Understand how normalization is used in the database design process

Page 4: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

4

5

Concepts of Database Management

Normalization

Normalization process – enables you to identify the existence of potential problems, called updating anomalies, in the design of a relational database

Normal form – possesses a certain desirable collection of properties

Page 5: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

5

5

Concepts of Database Management

Figure 5.1:Premiere Products Data

Page 6: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

6

5

Concepts of Database Management

Functional Dependence

Column B is functionally dependent on Column A if A’s value determines a single value for B at a given time

Given A, a single value for B can be determined

Page 7: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

7

5

Concepts of Database Management

Functional Dependence

Page 8: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

8

5

Concepts of Database Management

Figures 5.3-5.4:Functional Dependence Example

Rep Table Where LastName can determine record

Rep Table Where LastName cannot determine record

Page 9: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

9

5

Concepts of Database Management

Keys Column(s) C is primary key for table T if:

Property 1: All columns in T are functionally dependent on C

Property 2: No subcollection of columns in C (assuming C is a collection of columns and not just a single column) also has Property 1

Candidate Keys Column(s) on which all other columns in table are

functionally dependent

Alternate Keys Candidate keys not chosen as primary keys

Page 10: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

10

5

Concepts of Database Management

First Normal Form (1NF)

Unnormalized table

Contains a repeating group

Table in 1NF

Contains no repeating groups

Removal of repeating groups is starting point in quest for problem-free tables

Page 11: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

11

5

Concepts of Database Management

Figure 5.5: 1NF Example

Unnormalized Table

Page 12: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

12

5

Concepts of Database Management

Figure 5.6: 1NF Example (con’t.)

Conversion to 1NF

Page 13: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

13

5

Concepts of Database Management

Second Normal Form (2NF)

1NF Tables may contain problems Redundancy

Update Anomalies Update, inconsistent data, additions, deletions

Occur because a column is dependent on a portion of a multi-column primary key

2NF Table In 1NF and no nonkey column is dependent on

only a portion of the primary key

Page 14: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

14

5

Concepts of Database Management

Figure 5.7:Second Normal Form

Page 15: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

15

5

Concepts of Database Management

Update Anomalies Update

Information is in multiple rows, difficult to update

Inconsistent data Because of the duplication, a row that is not updated

causes inconsistency

Additions Dummy records are required to add new unused

dependent rows

Deletions Nonkey column (nonkey attribute) – when a

column is not a part of the primary key

Page 16: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

16

5

Concepts of Database Management

Dependency Diagram

Dependency diagram – uses arrows to indicate all the functional dependencies present in a table

Partial dependencies – dependencies only on a portion of the primary key

Page 17: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

17

5

Concepts of Database Management

Figure 5.8:Dependency Diagram for Orders

Page 18: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

18

5

Concepts of Database Management

Third Normal Form (3NF)

2NF Tables may still contain problems Redundancy and wasted space

Update Anomalies Update, inconsistent data, additions, deletions

Occur because a column is dependent on a portion of a multi-column primary key

3NF Table In 2NF and the only determinants contained are

candidate keys

Page 19: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

19

5

Concepts of Database Management

Figure 5.9: 2NF Example

Page 20: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

20

5

Concepts of Database Management

Figure 5.10: Sample Customer Data

Page 21: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

21

5

Concepts of Database Management

Figure 5.11:Customers Dependency Diagram

Page 22: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

22

5

Concepts of Database Management

Incorrect Decomposition

Decomposition must take place according to that described for 3NF

Even though you may decompose a table, you run the risk of splitting the functional dependence across different tables

Page 23: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

23

5

Concepts of Database Management

Figure 5.12: 3NF Example

Page 24: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

24

5

Concepts of Database Management

Figure 5.13: Incorrect Decomposition Example

Page 25: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

25

5

Concepts of Database Management

Fourth Normal Form (4NF)

3NF Tables may still contain problems

Dependencies

Update Anomalies

Update, additions, deletions

Occur because of multivalued dependencies

4NF Table

In 3NF and has no multivalued dependencies

Page 26: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

26

5

Concepts of Database Management

Figure 5.15: Incorrect 4NF Example

Page 27: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

27

5

Concepts of Database Management

Figure 5.16a: 4NF Example

Page 28: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

28

5

Concepts of Database Management

Figure 5.17: Normal Forms

Page 29: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

29

5

Concepts of Database Management

Summary

Normalization is a process of optimizing databases to prevent update anomalies

Normalization attempts to correct update issues by eliminating duplication

Duplication also creates inconsistency

Insertions can violate database integrity if the database is not normalized

Deletions can violate database integrity if the database is not normalized

Page 30: Concepts of Database Management, Fifth Edition Chapter 5: Database Design 1: Normalization

30

5

Concepts of Database Management

Summary (con’t.)

Normal Forms – First (1NF), Second (2NF), Third(3NF), and Fourth(4NF)

1NF has no repeating groups

2NF is in 1NF and no non-key column is dependent on only a portion of the primary key

3NF is in 2NF and the only determinants are candidate keys

4NF is in 3NF and has no multivalued dependencies