Beruflich Dokumente
Kultur Dokumente
Normalization
of
Database
Tables
CHAPTER 6
Database
Systems
Rob &
Coronel 1
Chapter 5
Normalization Chapter Objectives
of
Database
Tables
Database
Systems
Rob &
Coronel 2
Chapter 5
Normalization Database Tables and Normalization
of
Database
Tables
Normalization is a process for assigning attributes
to entities.
It reduces data redundancies.
An unnormalized relation (table) stores redundant
data, which can cause insertion, deletion, and
modification anomalies.
In simple words: Normalization means keeping a
single copy of data in your database.
Normalization theory provides a step by step
method to remove redundant data and undesirable
Database
table structures.
Systems
Rob &
Coronel 3
Chapter 5
Normalization Normal Forms
of
Database
Tables
Tables are normalized by applying rules to create a
series of normal forms:
Firstnormal form (1NF)
Second normal form (2NF)
Third normal form (3NF)
Boyce/Codd normal form (BCNF)
Fourth normal form (4NF)
Projection Join normal form (PJNF, aka 5NF)
2NF Relations
3NF Relations
BCNF Relations
4NF Relations
Database
Systems
Rob &
Coronel 9
Chapter 5
Normalization Functional Dependency Revisited
of
Database
Tables
Full functional dependency
Attribute B is fully functionally dependent on
attribute A if it is functionally dependent on A and
not functionally dependent on any proper subset of
A.
This becomes an issue only with composite keys.
Transitive dependency
A, B and C are attributes of a relation such that
A B and B C, then C is transitively dependent on
A via B (provided that A is not functionally
dependent on B or C)
Database
Systems
Rob &
Coronel 10
Chapter 5
Normalization Second Normal Form
of
Database
Tables
Dependency diagram for Project
Database
Systems
Rob &
Coronel 11
Chapter 5
Normalization Second Normal Form
of
Database
Tables
A relation is in 2NF if:
It is in 1NF and
every nonkey attribute is fully dependent on the
primary key, i.e., no partial dependency.
A nonkey attribute is one that is not a primary key or
part of a primary key.
We create new relations that are in 2NF through
projection of the original relation.
Project(PNo, PName)
Employee(ENo, EName, Jcode, ChgHr)
Charge(PNo, ENo, Hrs)
Database
Systems
Rob &
Coronel 12
Chapter 5
Normalization Second Normal Form
of
Database
Tables
Tables in 2NF Charge
Project PNo ENo Hrs
PNo PName 1 101 20
1 Alpha 1 105 15
2 Beta 1 110 40
3 Omega 2 101 20
2 108 15
2 106 20
Employee 3 102 20
ENo EName JCode ChgHr 3 105 10
101 John Doe NE $65
102 Beth Reed PM $125
105 Jane Vo SA $80
106 Sara Lee SA $80
108 Jeb Lee NE $65
110 Bob Lund CP $60
Database
Systems
Rob &
Coronel 13
Chapter 5
Normalization Second Normal Form
of
Database
Tables
Note that the original relation can be recreated
through natural join of the new relation.
Thus, no information is lost in the process of
creating 2NF relations from a 1NF relation. This is
called nonloss decomposition.
If a relation that is in 1NF has a non composite
primary key (i.e., the primary key consists of a
single attribute) what can you say about its status
with regard to 2NF?
Do you see any redundant data in the tables that are
in 2NF?
Database
Systems
Rob & What anomalies could be caused by such
Coronel 14
redundancy?
Chapter 5
Normalization Third Normal Form
of
Database
Tables
A relation is in 3NF if:
It is in 2NF and
every nonkey attribute is nontransitively
dependent on the primary key (i.e., no transitive
dependency).
Relation Employee has a transitive dependency:
ENo JCode ChgHr
Employee can be replaced by two relations, that are
in 3NF:
Employee(ENo, EName, Jcode)
Database
Systems Job(JCode, ChgHr)
Rob &
Coronel 15
Chapter 5
Normalization Third Normal Form
of
Database
Tables
Tables in 3NF Charge
Project PNo ENo Hrs
PNo PName 1 101 20
1 Alpha 1 105 15
2 Beta 1 110 40
3 Omega 2 101 20
2 108 15
2 106 20
3 102 20
Employee 3 105 10
ENo EName Jcode
101 John Doe NE Job
102 Beth Reed PM Jcode ChgHr
105 Jane Vo SA CP $60
106 Sara Lee SA NE $65
Database 108 Jeb Lee NE PM $125
Systems 110 Bob Lund CP SA $80
Rob &
Coronel 16
Chapter 5
Normalization Boyce-Codd Normal Form
of
Database
Tables
A relation is in BCNF if
every determinant is a candidate key.
A determinant is an attribute (combination of attributes) on
which some other attribute is fully functionally dependent.
BCNF is a special case of 3NF.
The potential to violate BCNF may occur in a
relation that:
contains two (or more) composite candidate keys,
these keys overlap and share at least one attribute.
Database
Systems
Rob &
Coronel 22
Chapter 5
Normalization Denormalization
of
Database
Tables
Normalized (decomposed) tables require additional
processing, thus reducing system speed.
Sometimes normalization is not done keeping in
mind processing speed requirements and practical
aspects of the situation.
A good example is: storing Zip code and City as
attributes in a Customer relation violates 3NF
because City is transitively dependent on Cust ID
via Zip Code.
Why should we not create a separate relation
ZIP (ZipCode, City)?
Database
Systems
Rob &
Coronel 23