28
© Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

Embed Size (px)

Citation preview

Page 1: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 1

Normalization

Bayu Adhi Tama, M.T.I.

Faculty of Computer ScienceUniversity of Sriwijaya

Page 2: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 2

Normalization

A technique for producing a set of tables with desirable properties that support the requirements of a user or company.

Page 3: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

3

Purpose of Normalization

The benefits of using a database that has a suitable set of relations is that the database will be: easier for the user to access and

maintain the data; take up minimal storage space on

the computer.

Page 4: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 4

Data redundancy and update anomalies Major aim of relational database

design is to group columns into tables to minimize data redundancy and reduce file storage space required by base tables.

Problems associated with data redundancy are illustrated by comparing the Staff and Branch tables with the StaffBranch table.

Page 5: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 5

Data redundancy and update anomalies

Page 6: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 6

Data redundancy and update anomalies

Page 7: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 7

Data redundancy and update anomalies StaffBranch table has redundant

data; the details of a branch are repeated for every member of staff.

In contrast, the branch information appears only once for each branch in the Branch table and only the branch number (branchNo) is repeated in the Staff table, to represent where each member of staff is located.

Page 8: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 8

Data redundancy and update anomalies Tables that contain redundant

information may potentially suffer from update anomalies.

Types of update anomalies include insertion deletion modification

Page 9: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 9

Functional dependency

The particular relationships that we show between the columns of a table are more formally referred to as functional dependencies.

Functional dependency describes the relationship between columns in a table.

Page 10: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

10

Functional Dependencies Important concept associated with

normalization. Functional dependency describes

relationship between attributes. For example, if A and B are attributes

of relation R, B is functionally dependent on A (denoted A B), if each value of A in R is associated with exactly one value of B in R.

© Pearson Education Limited 1995, 2005

Page 11: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

11

Characteristics of Functional Dependencies

Diagrammatic representation.

The determinant of a functional dependency refers to the attribute or group of attributes on the left-hand side of the arrow.

© Pearson Education Limited 1995, 2005

Page 12: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

12

An Example Functional Dependency

© Pearson Education Limited 1995, 2005

Page 13: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

13

Example - Identifying a set of functional dependencies for the StaffBranch relation

Examine semantics of attributes in StaffBranch relation. Assume that position held and branch determine a member of staff’s salary.

© Pearson Education Limited 1995, 2005

Page 14: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

14

Example - Identifying a set of functional dependencies for the StaffBranch relation

With sufficient information available, identify the functional dependencies for the StaffBranch relation as:

staffNo → sName, position, salary, branchNo, bAddress

branchNo → bAddressbAddress → branchNobranchNo, position → salarybAddress, position → salary

© Pearson Education Limited 1995, 2005

Page 15: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

15

Example - Using sample data to identify functional dependencies.

Consider the data for attributes denoted A, B, C, D, and E in the Sample relation.

Important to establish that sample data values shown in relation are representative of all possible values that can be held by attributes A, B, C, D, and E. Assume true despite the relatively small amount of data shown in this relation.

© Pearson Education Limited 1995, 2005

Page 16: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

16

Example - Using sample data to identify functional dependencies.

© Pearson Education Limited 1995, 2005

Page 17: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 17

First normal form (1NF)

Only 1NF is critical in creating appropriate tables for relational databases. All subsequent normal forms are optional.

A table in which the intersection of every column and record contains only one value.

Page 18: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 18

Branch table is not in 1NF

Page 19: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 19

Converting Branch table to 1NF

Page 20: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 20

Second normal form (2NF) Formal definition of 2NF is a table

that is in 1NF and every non-primary-key column is fully functional dependent on the primary key.

Full functional dependency indicates that if A and B are columns of a table, B is fully dependent on A if B is functionally dependent on A but not on any proper subset of A.

Page 21: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 21

TempStaffAllocation table is not in 2NF

Page 22: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 22

Converting TempStaffAllocation table to 2NF

Page 23: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 23

Third normal form (3NF)

The formal definition of 3NF is a table that is in 1NF and 2NF and in which no non-primary-key column is transitively dependent on the primary key.

Page 24: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 24

Third normal form (3NF)

For example, consider a table with A, B, and C. If B is functional dependent on A (A B) and C is functional dependent on B (B C), then C is transitively dependent on A via B (provided that A is not functionally dependent on B or C).

If a transitive dependency exists on the primary key, the table is not in 3NF.

Page 25: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 25

StaffBranch table is not in 3NF

Page 26: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

© Pearson Education Limited, 2004 26

Converting the StaffBranch table to 3NF

Page 27: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

Exercise

Identify functional dependencies for the table. Describe and illustrate the process of normalizing the

table to 3NF.

27

Page 28: © Pearson Education Limited, 2004 1 Normalization Bayu Adhi Tama, M.T.I. Faculty of Computer Science University of Sriwijaya

Exercise(2)

© Pearson Education Limited, 2004 28

• What normal form is the table in? • Describe and illustrate the process of normalizing the table to

higher normal form (3NF).