Top Banner
MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization Walailuk University MIT 533 ระบบฐานขอมูล 2 PDF created with pdfFactory Pro trial version www.pdffactory.com
64

Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

May 21, 2020

Download

Documents

dariahiddleston
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: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

MIT-533 Database Systems 2 Lecture 2: Normalization 1

Lecture 2 Normalization

Walailuk University

MIT 533 ระบบฐานขอมูล 2

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 2: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 2MIT-533 Database Systems 2

Objectivesn The purpose of normalizationn The identification of various types of update anomalies n The concept of functional dependencyn How functional dependencies can be used to group

attributes into relations that are in a known normal form.n How to undertake the process of normalization.n How to identify the most commonly used normal forms,

namely first (1NF), second (2NF), and third (3NF)normal forms, and Boyce–Codd normal form (BCNF).

n How to identify fourth (4NF), and fifth (5NF) normalforms.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 3: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 3MIT-533 Database Systems 2

Normalization(Overview - I)n Main objective in developing a logical data model

for relational database systems is to create an accurate representation of the data, its relationships, and constraints.

n To achieve this objective, we must identify a suitable set of relations.

n A technique for producing a set of relations with desirable properties, given the data requirements of an enterprise.

n Developed by E.F. Codd (1972).

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 4: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 4MIT-533 Database Systems 2

Normalization(Overview - II)

n Often performed as a series of tests on a relation to determine whether it satisfies or violates the requirements of a given normal form.

n Four most commonly used normal forms are first (1NF), second (2NF), third (3NF) and Boyce-Codd(BCNF) normal forms.

n Based on functional dependencies among the attributes of a relation.

n A relation can be normalized to a specific form to prevent the possible occurrence of update anomalies.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 5: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 5MIT-533 Database Systems 2

Purpose of Normalizationn Normalization is a technique for producing a

set of suitable relations that support the data requirements of an enterprise.

n Characteristics of a suitable set of relations include: ¨ the minimal number of attributes necessary to

support the data requirements of the enterprise;¨attributes with a close logical relationship are

found in the same relation;¨minimal redundancy with each attribute

represented only once with the important exception of attributes that form all or part of foreign keys.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 6: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 6MIT-533 Database Systems 2

Purpose of Normalizationn 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.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 7: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 7MIT-533 Database Systems 2

How Normalization Supports DB Design

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 8: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 8MIT-533 Database Systems 2

Data Redundancyn Major aim of relational database design is to

group attributes into relations to minimize data redundancy and reduce file storage space required by base relations.

n Problems associated with data redundancy are illustrated by comparing the Staff and Branch relations with the StaffBranch relation.StaffBranch: (staffNo, sName, position, salary, branchNo, bAddress)

Staff: (staffNo, sName, position, salary, branchNo)Branch: (branchNo, bAddress)

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 9: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 9MIT-533 Database Systems 2

Data Redundancy(An Example)

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 10: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 10MIT-533 Database Systems 2

Data Redundancy(Explanation to the example)n StaffBranch relation has redundant data¨details of a branch are repeated for every

member of staff.n In contrast, branch information appears only

once for each branch in Branch relation and only branchNo is repeated in Staff relation, to represent where each member of staff works.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 11: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 11MIT-533 Database Systems 2

Update Anomaliesn Relations that contain redundant information may

potentially suffer from update anomalies.n Types of update anomalies include¨ Insertion nDuplicate bAddress (new staff)nNull staffNo (new branch)

¨DeletionnSome bAddress may be lost.

¨ModificationnNeed to update all occurrences of bAddress, if it

is changed.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 12: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 12MIT-533 Database Systems 2

Lossless-join and Dependency Preservation Properties

n To avoid update anomalies, we decompose a large relation into two or more relations.

n Two important properties of decomposition.¨Lossless-join property enables us to find any

instance of the original relation from corresponding instances in the smaller relations.

¨Dependency preservation property enables us to enforce a constraint on the original relation by enforcing some constraint on each of the smaller relations.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 13: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 13MIT-533 Database Systems 2

Functional Dependency (I)n Main concept associated with normalization

is functional dependencyn Functional Dependency¨Describes the relationship between attributes in

a relation. ¨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.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 14: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 14MIT-533 Database Systems 2

Functional Dependency (II)n Property of the meaning or semantics of the

attributes in a relation.n The determinant of a functional dependency

refers to the attribute or group of attributes on the left-hand side of the arrow.

n Diagrammatic representation.

determinant

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 15: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 15MIT-533 Database Systems 2

Functional Dependency(An Example)

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 16: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 16MIT-533 Database Systems 2

How to Find Functional Dependency(Normalization)n One approach to identifying the set of all possible values

for attributes in a relation is to more clearly understand the purpose of each attribute in that relation.¨ For example, the purpose of the values held in the staffNo

attribute is to uniquely identify each member of staff while the purpose of the values held in the sName attribute is to hold the names of members of staff.

n Main characteristics of functional dependencies used in normalization:¨ have a 1:1 or M:1 relationship between attribute(s) on left

and right-hand side of a dependency;¨ hold for all time;¨ are nontrivial.

trivial: staffNo, sNameà sNamestaffNo, sNameà staffNo

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 17: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 17MIT-533 Database Systems 2

Example Functional Dependency that holds for all Timen Consider the values shown in staffNo and sName

attributes of the Staff relation. n Based on sample data, the following functional

dependencies appear to hold.staffNo→ sNamesName→ staffNo

n However, the only functional dependency that remains true for all possible values for the staffNoand sName attributes of the Staff relation is:

staffNo→ sName

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 18: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 18MIT-533 Database Systems 2

Properties: Functional Dependenciesn Determinants should have the minimal number

of attributes necessary to maintain the functional dependency with the attribute(s) on the right hand-side.

n This requirement is called full functional dependency.

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

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 19: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 19MIT-533 Database Systems 2

Example Full Functional Dependencyn Exists in the Staff relation

staffNo, sName→ branchNon True - each value of (staffNo, sName) is

associated with a single value of branchNo. n However, branchNo is also functionally

dependent on a subset of (staffNo, sName), namely staffNo. Example above is a partial dependency. The full dependency will be as follows.

staffNo→ branchNo

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 20: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 20MIT-533 Database Systems 2

Characteristics of Functional Dependenciesn Main characteristics of functional dependencies used

in normalization:¨There is a one-to-one relationship between the

attribute(s) on the left-hand side (determinant) and those on the right-hand side of a functional dependency.

¨Holds for all time.¨The determinant has the minimal number of

attributes necessary to maintain the dependency with the attribute(s) on the right hand-side.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 21: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 21MIT-533 Database Systems 2

Identifying Functional Dependenciesn Identifying all functional dependencies between a set of

attributes is relatively simple if the meaning of each attributeand the relationships between the attributes are well understood.

n This information should be provided by the enterprise in the form of discussions with users and/or documentation such as the users’ requirements specification.

n However, if the users are unavailable for consultation and/or the documentation is incomplete then depending on the database application it may be necessary for the database designer to use their common sense and/or experience to provide the missing information.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 22: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 22MIT-533 Database Systems 2

Example - Identifying a set of functional dependencies for the StaffBranch relationn Examine semantics of attributes in StaffBranch relation

described previously. Assume that position held and branch determine a member of staff’s salary.

n With sufficient information available, identify the functional dependencies for the StaffBranch relation as:staffNo→ sName, position, salary, branchNo, bAddressbranchNo→ bAddressbAddress→ branchNobranchNo, position → salarybAddress, position → salary

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 23: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 23MIT-533 Database Systems 2

Example - Using sample data to identify functional dependenciesn Consider the data for attributes denoted A, B,

C, D, and E in the Sample relation. n 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.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 24: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 24MIT-533 Database Systems 2

Example - Using sample data to identify functional dependencies

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 25: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 25MIT-533 Database Systems 2

Example - Using sample data to identify functional dependenciesn Function dependencies between attributes A to

E in the Sample relation.

A → C (fd1)C → A (fd2)B → D (fd3)A, B → E (fd4)

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 26: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 26MIT-533 Database Systems 2

Identifying the Primary Key for a Relation using Functional Dependenciesn Main purpose of identifying a set of functional

dependencies for a relation is to specify the set of integrity constraints that must hold on a relation.

n An important integrity constraint to consider first is the identification of candidate keys, one of which is selected to be the primary key for the relation.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 27: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 27MIT-533 Database Systems 2

Example - Identify Primary Key for StaffBranch Relationn StaffBranch relation has five functional

dependencies.n The determinants are staffNo, branchNo, bAddress,

(branchNo, position), and (bAddress, position).n To identify all candidate key(s), identify the

attribute (or group of attributes) that uniquely identifies each tuple in this relation.

staffNo→ sName, position, salary, branchNo, bAddressbranchNo→ bAddressbAddress→ branchNobranchNo, position → salarybAddress, position → salary

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 28: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 28MIT-533 Database Systems 2

Example - Identifying Primary Key for StaffBranch Relationn All attributes that are not part of a candidate key

should be functionally dependent on the key.n The only candidate key and therefore primary key for

StaffBranch relation, is staffNo, as all other attributes of the relation are functionally dependent on staffNo.

n Moreover there is one more primary, that is branchNo. It will be the primary key for Branch relation.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 29: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 29MIT-533 Database Systems 2

Example - Identifying Primary Key for Sample Relationn Sample relation has four functional dependencies.n The determinants in the Sample relation are A, B, C,

and (A, B). However, the only determinant that functionally determines all the other attributes of the relation is (A, B).

n (A, B) is identified as the primary key for this relation.

A → C (fd1)C → A (fd2)B → D (fd3)A, B → E (fd4)

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 30: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 30MIT-533 Database Systems 2

The Process of Normalizationn Formal technique for analyzing a relation based on its

primary key and the functional dependencies between the attributes of that relation.

n Often executed as a series of steps. Each step corresponds to a specific normal form, which has known properties.

n As normalization proceeds, the relations become progressively more restricted (stronger) in format and also less vulnerable to update anomalies.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 31: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 31MIT-533 Database Systems 2

Relationship Between Normal Forms

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 32: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 32MIT-533 Database Systems 2

Unnormalized Form (UNF) and First Normal Form (1NF)n Unnormalized Form (UNF)¨A table that contains one or more repeating groups.¨To create an unnormalized table nTransform the data from the information source

(e.g. form) into table format with columns and rows.

n First Normal Form (1NF)¨A relation in which the intersection of each row

and column contains one and only one value.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 33: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 33MIT-533 Database Systems 2

UNF to 1NFn Identify the repeating group(s) in the

unnormalized table which repeats for the key attribute(s).

n Remove the repeating group by¨ Entering appropriate data into the empty columns of rows

containing the repeating data (‘flattening’ the table).OR¨ Nominate an attribute or group of attributes to act as the

primary key for the unnormalized table and then placing the repeating data along with a copy of the original key attribute(s) into a separate relation.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 34: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 34MIT-533 Database Systems 2

UNF to 1NF(An Example – Form)

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 35: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 35MIT-533 Database Systems 2

UNF to 1NF(An Example – Transformation Result)

UNF

1NF

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 36: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 36MIT-533 Database Systems 2

UNF to 1NF(An Example – Alternative Transformation Result)

UNF

1NF

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 37: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 37MIT-533 Database Systems 2

Second Normal Form (2NF)n Based on the concept of full functional

dependency.n Full functional dependency indicates that¨A and B are attributes of a relation, ¨B is fully dependent on A if B is functionally

dependent on A but not on any proper subset of A.n 2NF – A relation that is in 1NF and every non-

primary-key attribute is fully functionally dependent on the primary key.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 38: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 38MIT-533 Database Systems 2

1NF to 2NFn Identify the primary key for the 1NF relation.n Identify the functional dependencies in the

relation.n If partial dependencies exist on the primary

key remove them by placing then in a new relation along with a copy of their determinant.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 39: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 39MIT-533 Database Systems 2

1NF to 2NF(An Example – Functional Dependency)

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 40: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 40MIT-533 Database Systems 2

1NF to 2NF(An Example – Transformation Result)

1NF

2NF

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 41: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 41MIT-533 Database Systems 2

Third Normal Form (3NF)n Based on the concept of transitive dependency.¨A, B and C are attributes of a relation such that if A à

B and B à C, ¨ then C is transitively dependent on A through B.

(Provided that A is not functionally dependent on B or C).

n 3NF – A relation that is in 1NF and 2NF and in which no non-primary-key attribute is transitively dependent on the primary key.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 42: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 42MIT-533 Database Systems 2

2NF to 3NFn Identify the primary key in the 2NF relation.n Identify functional dependencies in the relation.n If transitive dependencies exist on the primary key remove

them by placing them in a new relation along with a copy of their dominant.

n Second normal form (2NF)¨ A relation that is in 1NF and every non-primary-key

attribute is fully functionally dependent on any candidate key.

n Third normal form (3NF)¨ A relation that is in 1NF and 2NF and in which no non-

primary-key attribute is transitively dependent on any candidate key.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 43: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 43MIT-533 Database Systems 2

2NF to 3NF(An Example – Transformation Result)

2NF

3NF

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 44: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 44MIT-533 Database Systems 2

Summary Result of Normalization (I)

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 45: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 45MIT-533 Database Systems 2

Summary Result of Normalization (II)

UNF

3NF

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 46: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 46MIT-533 Database Systems 2

Boyce-Codd Normal Form (BCNF)n Based on functional dependencies that takes into

account all candidate keys in a relation. n However, BCNF also has additional constraints

compared with general definition of 3NF.n For a relation with only one candidate key, 3NF and

BCNF are equivalent.n A relation is in BCNF, if and only if every

determinant is a candidate key.n Violation of BCNF may occur in a relation that¨ contains two (or more) composite keys¨ which overlap and share at least one attribute in common.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 47: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 47MIT-533 Database Systems 2

Difference between 3NF and BCNFn Difference between 3NF and BCNF is that for a

functional dependency A à B, 3NF allows this dependency in a relation if B is a primary-key attribute and A is not a candidate key.

n Whereas, BCNF insists that for this dependency to remain in a relation, A must be a candidate key.

n Every relation in BCNF is also in 3NF. However, relation in 3NF may not be in BCNF.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 48: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 48MIT-533 Database Systems 2

3NF to BCNFn Identify all candidate keys in the relation.n Identify all functional dependencies in the

relation.n If functional dependencies exists in the relation

where their determinants are not candidate keys for the relation, remove the functional dependencies by placing them in a new relation along with a copy of their determinant.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 49: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 49MIT-533 Database Systems 2

3NF to BCNF(An Example)

3NF

BCNF

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 50: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 50MIT-533 Database Systems 2

Review of Normalization (Original Form)

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 51: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 51MIT-533 Database Systems 2

Review of Normalization (UNF to 1NF)UNF

1NF

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 52: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 52MIT-533 Database Systems 2

Review of Normalization (Functional Dependency)

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 53: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 53MIT-533 Database Systems 2

Review of Normalization (Final Result)

StaffPropertyInspection(propertyNo, iDate, iTime, pAddress, comments, staffNo, sName, carReg)PropertyInspection (propertyNo, iDate, iTime, comments, staffNo, sName, carReg)

PropertyInspect (propertyNo, iDate, iTime, comments, staffNo, carReg)

StaffCat (staffNo, iDate, carReg)

Inspection (propertyNo, iDate, iTime, comments, staffNo)Staff (staffNo, sName)

Property (propertyNo, pAddress)

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 54: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 54MIT-533 Database Systems 2

Fourth Normal Form (4NF)n Although BCNF removes anomalies due to

functional dependencies, another type of dependency called a multi-valued dependency(MVD) can also cause data redundancy.

n MVDs in a relation are due to first normal form (1NF), which disallows an attribute in a row from having a set of values.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 55: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 55MIT-533 Database Systems 2

Fourth Normal Form (4NF) – MVDn Represents a dependency between attributes (for example, A,

B, and C) in a relation, such that for each value of A there is a set of values for B, and a set of values for C. However, the set of values for B and C are independent of each other.

n MVD between attributes A, B, and C in a relation using the following notation:

A à> B A à> C

n A 4NF relation that is in Boyce-Codd Normal Form (BCNF) and contains no MVDs.

n BCNF to 4NF involves the removal of the MVD from the relation by placing the attribute(s) in a new relation along with a copy of the determinant(s).

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 56: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 56MIT-533 Database Systems 2

BCNF to 4NF (An Example)

BCNF

4NF

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 57: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 57MIT-533 Database Systems 2

Fifth Normal Form (5NF)n A relation decomposed into two relations must have

lossless-join property, which ensures that no spurious tuples are generated when relations are reunited through a natural join.

n However, there are requirements to decompose a relation into more than two relations.

n Although rare, these cases are managed by join dependency and fifth normal form (5NF).

n 5NF ¨A relation that has no join dependency.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 58: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 58MIT-533 Database Systems 2

Fifth Normal Form (5NF)(An Example)n Consider the following statement:

If Property PG4 requires BedSupplier S2 supplies property PG4Supplier S2 provides Bed

ThenSupplier S2 provides Bed for property PG4

n To identify this type of constraint on the PropertyItemSupplier relation, use 5NF

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 59: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 59MIT-533 Database Systems 2

4NF to 5NF (An Example)

5NF

4NF

INCORRECT

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 60: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 60MIT-533 Database Systems 2

Exercise In Normalize the following relationLecturer_Course_Rel(DID, Dept, LID, Lname, Lroom, CID, CName,

Credit, DW, LTime, PID, PType)DID Dept. LID LName CID CName Credit LRoom LTime DW PID PType

101 Intro. To Comp 2-3 101 13:00-16:00 Mon. 01 Sony 0001 Minger 105 Prog. Lang. 3-0 101 9:00-10:20 Tue. 02 Panasonic 003 Math II 2-0 102 10:40-12:00 Thu. 04 Phillips 10 IT

0002 Craven 105 Prog. Lang. 3-0 106 14:40-16:00 Wed. 02 Panasonic 003 Math II 2-0 201 13:00-14:20 Thu. 01 Sony 0101 Taylor 208 Fluid Dynamics 2-3 101 9:00-12:00 Mon 01 Sony 11 ME

0102 Chen 208 Fluid Dynamics 2-3 202 14:40-16:00 Fri. 04 Phillips 0201 Ahmed 307 Concrete Eng. 2-3 301 13:00-14:20 Tue. 05 Sharp 12 CE 0202 Brown 304 Hydraulics 3-0 106 9:00-10:20 Wed. 02 Panasonic

Where,DID: Department IdentifierDept: Department NameLID: Lecture IdentifierLecturer: Lecturer Name

LRoom: Lecture RoomCID: Course IdentifierCourse: Course NameLTime: Lecture TimeDW: Day in WeekPID: Projector IdentifierPType: Projector Type

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 61: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 61MIT-533 Database Systems 2

Exercise IIn Normalize the following form.

ABC HospitalPatient Medication Form

Full Name: Peter PakinsonBed Number: 1205

Ward Number: Ward 11Ward Name: Orthopaedic

28/05/0425/04/0410Oral10 mg/mlPain KillerMorphine10223

24/05/0424/03/0410IV0.5 mg/mlAntibioticTetracyclene10334

24/04/0424/03/0450Oral10 mg/mlPain KillerMorphine10223

Finish Date

Start Date

Units per day

Method of Admin

DosageDescriptionNameDrug No.

Created By: Ms PatanaCreated Date: 23/03/04

Date: 23/03/2004

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 62: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 62MIT-533 Database Systems 2

Exercise IIIn Normalize the following form.

1000JerryR0310:0024/05/04KingstonTony Smith

102

2000JenniferR0513:0022/05/04MiceMary Mind105

2000MaryR3415:0028/05/04MiceJohn Robin

104

2400MaryR349:0028/05/04SusanTony Smith

102

1200NancyR0311:0026/05/04JimHelen Peter

101

FeeNurseRoomApp. Time

App. Date

Patient Name

Doctor Name

Staff No.

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 63: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 63MIT-533 Database Systems 2

Exercise IVn Normalize the following form.

1512/02/05M2347234SonyJohnHarry Plotter (I)1001

2015/01/05M2313454Paramount

Phillip13 Ghosts1205

2002/02/05M2142344SonyJohnHarry Plotter (I) 2043

3014/06/04M1562342Paramount

NickArmageddon3113

2013/07/04M2342342Paramount

NickArmageddon3113

FeeRentalDate

MemberID

BarcodeProducerArtistMovie NameCDID

PDF created with pdfFactory Pro trial version www.pdffactory.com

Page 64: Lecture 2 Normalization - Khon Kaen University...MIT-533 Database Systems 2 Lecture 2: Normalization 1 Lecture 2 Normalization ... (1NF), second (2NF), andthird (3NF) normalforms,

Lecture 2: Normalization 64MIT-533 Database Systems 2

Exercise Vn Find functional dependency/normalize the following table.

pwjgdaqwlhearzkifapwjgdbswmgebszmhfbuwoidc

rzkifcqwlhec

FEDCBA

PDF created with pdfFactory Pro trial version www.pdffactory.com