Chapter 5
Chapter 5
1
Normalization
Normalization of Relations:
BOTTOM UP DESIGN
Normalization
Normalization
The Steps
Normalization
Normalization
Functional Dependencies
A relational table is one way of describing the way in which
several attributes interact, or depend on each other. The simplest
kind of dependency is called functional dependency (FD).
For example,
LecturerID LecturerName
is a valid FD because:
• For each LecturerID there is at most one LecturerName, or
• LecturerName is determined by LecturerID , or
• LecturerName is uniquely determined by LecturerID , or
• LecturerName depends on LecturerID .
Anomalies?:
o If there is a new subject which has not been allocated a
lecturer, can you record the details of this subject in the above
table? (Insert Anomaly)
o If an existing subject changes it’s title, can you do the changes
to once instance only? (Update Anomaly)
o If a lecturer resigns and the details are to be deleted, would
there be a chance that some subjects will be removed
permanently and we won’t have any track record of those
subjects anymore? (Delete Anomaly)
Normalization
Normalization
Normalization
Normalization
NORMAL FORMS
-- A relation is in 2NF if :
- the relation is in 1 NF
- all non-key attributes are fully functionally dependent on the
entire key (partial dependency has been removed).
Normalization
Normalization
NORMAL FORMS
-- A relation is in BCNF if :
Normalization
Normalization
NORMAL FORMS
-- A relation is in 5NF if :
Normalization
Normalization
Example
Transform the ORDER form below into BCNF relations.
ORDER FORM
Order #: 5258
Customer # : 32
Customer Name : Computer Training Center
Customer Address: 1, Plenty Road
City-State-Post Code: Bundoora, VICTORIA 3083
Order Date: 20/ 2/ 2009
P ro d u c t # D e s c rip t io n Q u a n t it y Un it P ric e
P 123 Bo o k Cas e 4 200
P 234 C a bine t 2 150
P 345 Ta ble 1 500
Normalization
Solution
From the ORDER FORM (user view) we can derive ORDER relation:
To convert the above relation into 1NF, the repeating group must be removed
by creating a new relation based on the repeating group along with the primary
key of the main relation:
Normalization
Solution( ctd)
-- 1NF:
ORDER( Order#, Customer#, Customer Name, Customer Address,
CityStatePostCode, OrderDate)
ORDER_PRODUCT
O ( Order#, Product#, Description, Quantity, Unit Price)
Anomalies:
Insertion Anomalies: cannot insert a new product until there is an order for
that product.
Deletion Anomalies: if an order is deleted the whole detail of the product will
also be deleted.
Solution( ctd)
--2NF
The ORDER relation is already in 2NF as there are no non key attributes
that are dependent on partial key (ORDER only has a single key).
Normalization
Solution( ctd)
--2NF
Anomalies
Insert Anomalies : a new customer cannot be inserted until he/she has an order.
--3NF
The ORDER relation is not in 3NF because there is a transitive dependency (non-
key attribute dependent on another non-key attribute).
To convert the relation into 3NF, a new relation must be created for the non-key
attributes that are dependent to another non-key attribute.
Both the order ORDER_PRODUCT and the PRODUCT relations are already in 3NF.
CUSTOMER BRANCH
M M
(1:N) (1:N)
Branch-
Customer
VisitingFrequency
DateRelationship Established
1 (0:N)
SalespersonNo
SALESPERSON
BCNF (Boyce Codd Normal Form)
BRANCH-CUSTOMER
(CustomerNo, BranchNo, SalespersonNo, VisitingFrequency,
DateRelationshipEstablished)
1. The table enforces the rule that each branch will serve a
customer through only one salesperson, as there is only one
SalespersonNo for each combination of CustomerNo and
BranchNo.
2. The table is in 3NF(there are no repeating groups, no partial
and transitive dependencies). If each salesperson works for
one branch only, the table still has some normalization
problems. The fact that a particular salesperson belongs to a
particular branch can appear in more than one row. In fact, it
will appear in every row for that salesperson.
Problem 1:
SALESPERSON (SalespersonNo, BranchNo)
Problem 2:
CUSTOMER-SALESPERSON (CustomerNo, SalespersonNo,
VisitingFrequency, DateRelationshipEstablished, BranchNo)
Solution:
CUSTOMER-SALESPERSON (CustomerNo, SalespersonNo,
VisitingFrequency, DateRelationshipEstablished)
SALESPERSON (SalespersonNo, BranchNo)
BCNF (Boyce Codd Normal Form)
BCNF:
o In the original table we enforced the rule that a given customer was
only served by one salesperson from each branch.
o Our new model no longer enforces that rule. It is now possible for a
customer to be supported by several salespersons from the same
branch.
o Generic Format:
3NF but not BCNF: R1 (A, B, C) where C may determine B
Converted to BNCF: R11 (A, C) and R12 (C, B)
BCNF (Boyce Codd Normal Form)
CustomerNo BranchNo
CUSTOMER BRANCH
M 1 (1:N)
(1:N)
VisitingFrequency
DateRelationship Established
employ
Customer-
Salesperson
M M
(1:N) (1:1)
SALESPERSON
SalespersonNo
Next Lecture …