lecture_7_5
lecture_7_5
Normalization
Create
Real-world Conceptual DBMS data Modify
Schema
domain model model data (DML)
(DDL)
2
Normalizatio
?How to produce a good relation schema
2. Define the functional dependencies for the relation to specify the PK.
3
Normalizatio
Data Redundancy and Update Anomalies
(branchNo) is repeated in
the Staff relation, to
represent where each
member of staff is located
Redundant
data
4
Pearson Education © 2009
Data Redundancy and Update Anomalies
Relations that contain redundant information may
potentially suffer from update anomalies.
5
Pearson Education © 2009
Relation Decomposition
Normalization process involve decomposing a relation.
Decomposition require to be reversible.
Functional dependencies guarantee decomposition to be
reversible.
While normalization, two important properties associated
with 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.
6
Pearson Education © 2009
Functional Dependencies
Describes the relationship between attributes in a relation.
If A and B are attributes of relation R,
B is functionally dependent on A, denoted A B, if each
value of A is associated with exactly one value of B. B may
have several values of A.
B is functionally
A dependent on A B
Determinant Dependent
An alternative way to describe the relation ship between
attribute A an B is to say that “ A functionally determines B”
7
Pearson Education © 2009
An Example Functional Dependency
1:1 or M:1
relationship
between
attributes in a
relation
1:M
relationship
between
attributes in a
relation
8
Pearson Education © 2009
Example Functional Dependency that holds for all Time
Consider the values shown in staffNo and sName
attributes of the Staff relation.
Based on sample data, the following functional
dependencies appear to hold.
staffNo → sName
sName → staffNo
11
Pearson Education © 2009
Transitive Dependencies
Important to recognize a transitive dependency because its
existence in a relation can potentially cause update anomalies.
12
Pearson Education © 2009
Example Transitive Dependency
Consider functional dependencies in the StaffBranch relation.
staffNo → sName, position, salary, branchNo, bAddress
branchNo → bAddress
14
Pearson Education © 2009
Identifying Functional Dependencies
There are two approach to Identifying all functional dependencies :
1. Identifying all functional dependencies between a set of attributes is
quite simple if the meaning of each attribute and the relationships
between the attributes are well understood.
This information should be provided by the enterprise (discussions
with users and/or documentation)
The missing information Ex: documentation is incomplete
(database designer use their common sense and/or experience).
15
Pearson Education © 2009
Example - Identifying a set of functional
dependencies for the StaffBranch relation
Identifing the functional dependencies for the StaffBranch
relation as:
Hint : Assume that position held and branch determine a member of staff’s
salary.
16
Pearson Education © 2009
Identifying the Primary Key for a Relation
using Functional Dependencies
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.
17
Pearson Education © 2009
Example - Identify Primary Key for
StaffBranch Relation
StaffBranch relation has five functional dependencies.
staffNo → sName, position, salary, branchNo, bAddress
branchNo → bAddress
bAddress → branchNo
branchNo, position → salary
bAddress, position → salary
CB B
A C
X A B
t
X+ A C
u
Armstrong’s axioms (inference rules): The set of inference rules specifies how
functional dependencies can be inferred from given one.
Inference rules:
Reflexivity If B A, then A B
Augmentation If A B, then A,C B,C
Transitivity If A B and B C, then A C
Self-Determination A A
Decomposition If A B,C, then A B and A C
Union If A B and A C, then A B,C
20
Normalizatio
Minimal Sets of Functional Dependencies
if S2 is a cover for S1
S1 equivalent to S2
& S1 is a cover for S2
21
Normalizatio
Minimal Sets of Functional Dependencies
3. Can’t remove any dependency from X and still have a set of dependencies that is
equivalent to X.
22
Normalizatio
Minimal Sets of Functional Dependencies
1. For each X {A1, A2, .. An}, create X A1, X A2, …., X An.
23
Normalizatio
Exercise
FD1: X →W
FD2.1: W, Z → X
FD2.2: W, Z → Y
FD3.1: Y → W
FD3.2 :Y→ X
FD4: X, Z → W
Exercise ( cont.)
FD1: X →W
FD2.1: W, Z → X
FD2.2: W, Z → Y
FD3.1: Y→W
FD3.2 :Y→ X
FD4: X, Z → W
FD1: X →W
FD2.1: W, Z → X
FD2.2: W, Z → Y
FD3.1:Y → W
FD3.2 :Y→ X
FD4: X, Z → W
Exercise ( cont.)
FD1: X →W
FD2.1: W, Z → X
FD2.2: W, Z → Y
FD3.1: Y→W
FD3.2 :Y→ X
Minimal set is :
FD1: X →W
FD2.2: W, Z → Y
FD3.2 :Y→ X
The Process of Normalization
1NF
2NF s
lie
a
m
3NF at no
orm e a
f at
BCNF n
i pd
r
e u
g
n to
4NF o
r le
St rab
5NF lne
vu
Higher Normal ess
L
Form
Normalization
28
The Purpose of Normalization
29
First Normal Form (1NF)
Unnormalized form (UNF): A relation that contains one or more repeating groups.
First normal form (1NF): A relation in which the intersection of each row and
column contains one & only one value.
CLIENT_PROPERTY
ClientNo Name PropertyNo
CR76 John Key PG4
PG16
CR56 Aline Stewart PG4
PG36
PG16
Unnormalized relation
30
Normalizatio
UNF 1NF
Approach 1
Expand the key so that there will be a separate tuple in the original relation for each
repeated attribute(s). Primary key becomes the combination of primary key and
redundant value.
CLIENT_PROPERTY
ClientNo Name PropertyNo
CR76 John Key PG4
CR76 John Key PG16
CR56 Aline Stewart PG4
CR56 Aline Stewart PG36
CR56 Aline Stewart PG16
1NF relation
CLIENT_PROPERTY
ClientNo Name PropertyNo1 PropertyNo2 PropertyNo3
CR76 John Key PG4 PG16 NULL
CR56 Aline Stewart PG4 PG36 PG16
1NF relation
32
Normalizatio
UNF 1NF
Approach 3
Remove the attribute that violates the 1NF and place it in a separate relation along
with a copy of the primary key.
CLIENT PROPERTY
ClientNo Name ClientNo PropertyNo
1NF relation
33
Normalizatio
Full Functional Dependency
34
Normalizatio
Second Normal Form (2NF)
Second normal form (2NF): A 1NF relation in which every attribute is fully
nontrivial functionally dependent on the PK. (non-prime attributes fully dependent
on PK.)
CLIENT_RENTAL
ClientNo PropertyNo cName pAddress RentStart RentFinish Rent OwnerNo OName
1NF relation
35
Normalizatio
1NF 2NF
36
Normalizatio
1NF 2NF
CLIENT_RENTAL
ClientNo PropertyNo cName pAddress RentStart RentFinish Rent OwnerNo OName
(ClientNo, PropertyNo) PK
37
Normalizatio
1NF 2NF
2NF relation
38
Normalizatio
Transitive Dependency
Example:
StaffNo BranchNo , BranchNo Address
StaffNo Address
39
Normalizatio
Third Normal Form (3NF)
CLIENT RENTAL
ClientNo cName ClientNo PropertyNo RentStart RentFinish
PROPERTY_OWNER
PropertyNo pAddress Rent OwnerNo OName
2NF relation
40
Normalizatio
2NF 3NF
OWNER PROPERTY_FOR_RENT
OwnerNo OName PropertyNo pAddress rent OwnerNo
41
Normalizatio
Review of Decompositions
1NF CLIENT_RENTAL
42
Normalizatio
General Definition of 2NF & 3NF
Second normal form (2NF): A 1NF relation in which every non-primary-key attribute
is fully functionally dependent on the CK.
43
Normalizatio
Review Example
STAFF_PROPERTY_INSPECTION
Pno pAddress iDate iTime comments StaffNo sName CarReg
PG4 Lawrence St, 18-Oct-00 10:00 Replace crockery SG37 Ann M23JGR
Glasgow 22-Apr-01 09:00 Good order SG14 David M53HDR
1-Oct-01 12:00 Damp rot SG14 David N72HFR
PG16 5 Novar Dr., 22-Apr-01 13:00 Replace carpet SG14 David M53HDR
Glasgow 24-Oct-01 14:00 Good condition SG37 Ann N72HFR
Unnormalized relation
44
Normalizatio
UNF 1NF
STAFF_PROPERTY_INSPECTION
Pno pAddress iDate iTime comments StaffNo sName CarReg
PG4 Lawrence St, Glasgow 18-Oct-00 10:00 Replace crockery SG37 Ann M23JGR
PG4 Lawrence St,Glasgow 22-Apr-01 09:00 Good order SG14 David M53HDR
PG4 Lawrence St,Glasgow 1-Oct-01 12:00 Damp rot SG14 David N72HFR
PG16 5 Novar Dr., Glasgow 22-Apr-01 13:00 Replace carpet SG14 David M53HDR
PG16 5 Novar Dr., Glasgow 24-Oct-01 14:00 Good condition SG37 Ann N72HFR
1NF
45
Normalizatio
1NF 2NF
STAFF_PROPERTY_INSPECTION
Pno iDate pAddress iTime comments StaffNo sName CarReg
46
1NF 2NF
PROPERTY
Pno pAddress Pno pAddress
2NF
PROPERTY_INSPECTION
Pno iDate iTime comments StaffNo sName CarReg
2NF
47
Normalizatio
2NF 3NF
PROPERTY
Pno pAddress
3NF
STAFF
StaffNo sName
3NF
PROPERTY_INSPECTION
Pno iDate iTime comments StaffNo CarReg
3NF
PROPERTY(Pno, pAddres)
STAFF(StaffNo, sName)
PROPERTY_INSPECT(Pno, iDate, iTime, comments, staffNo, CarReg)
48
Normalizatio