Chapter3 - Session2-Normal Forms
Chapter3 - Session2-Normal Forms
1
Outline
4 BCNF
1
2
Normal forms
Normalization works through a series of stages
called normal forms.
The first normal form (1NF), second normal form
(2NF), and third normal form (3NF).
From a structural point of view, 2NF is better than
1NF, and 3NF is better than 2NF.
For most purposes in business database design, 3NF
is as high as you need to go in the normalization
process.
Highest level of normalization is not always most
desirable
3
The process of normalization
4
First Normal Form (1NF)
A relation is in first normal form (1NF) if:
No multivalued attributes or no repeating groups
in the table. In other words, each row/column
intersection contains one and only one value, not
a set of values (Every attribute value is atomic)
A primary key has been defined, which uniquely
identifies each row in the relation
All relations are in 1st Normal Form
5
First Normal Form (1NF)
Example: Invoice tabular
Table with multivalued attributes, not in 1st normal form
7
First Normal Form (1NF)
Select the primary key
There are four determinants in INVOICE, and their
functional dependencies are the following:
10
Second Normal Form (2NF)
A relation is in second normal form (2NF) if:
It is in 1NF
There is no partial dependency.
A partial functional dependency exists when a
non-key attribute is functionally dependent on part
(but not all) of the primary key
If a relation in 1NF has a primary key with single
attribute, it is automatically in 2NF.
11
Second Normal Form (2NF)
Functional dependency diagram for INVOICE
13
Second Normal Form (2NF)
Removing partial dependencies
15
Exercises
Consider the following relations, check whether them
are in 2NF or not. If not, decompose it into 2NF.
Ex2: The relation R(A,B,C,D) and
F = { AB -> C, B -> D}.
Ex3: The relation R(A,B,C,D,E) and
F = { AB -> C, A -> D, B -> E}.
16
Third Normal Form (3NF)
A relation is in third normal form (3NF) if:
It is in 2NF
There is no transitive dependency.
A transitive dependency in a relation is a
functional dependency between the primary key
and one or more non-key attributes that are
dependent on the primary key via another non-
key attribute
In the other words, a transitive dependency
exists when a non-key attribute can determine
another non-key attribute
17
Third Normal Form (3NF)
There are 2 transitive dependencies in CustomerOrder
relation:
18
Third Normal Form (3NF)
Removing transitive dependencies by the following
steps:
1. For each non- key attribute(s) that is a determinant in a
relation, create a new relation. That attribute (s) becomes
the primary key of the new relation.
2. Move all of the attributes that are functionally dependent
on the primary key of the new relation from the old to the
new relation.
3. Primary key in the new relation serve as a foreign key in
the old relation.
19
Third Normal Form (3NF)
The results of applying the steps to the relation
CustomerOrder
20
Third Normal Form (3NF)
A relational schema showing these four relations and
their associations in ERD
21
Exercises
Ex1: Is the Inventory relation in 3 NF?
24
Boyce-codd Normal Form (BCNF)
A relation is in BCNF if:
It is in 3NF
For every functional dependency X-> Y, X (called
determinant) should be the candidate key of the
relation.
BCNF can be violated only when the table contains
more than one candidate key.
When a table contains only one candidate key, the
3NF and the BCNF are equivalent.
25
Boyce-codd Normal Form (BCNF)
Example 1: Is the following relation in BCNF?
R(A, B, C, D)
F= { A ->BCD; BC ->AD; D->B}
Above relation is in 3NF. Why?
2 Candidate keys is A and BC. Why?
But FD: D->B, D is not a candidate key.
So the relation R violates BCNF.
Thus, we break the relation R into 2 relation R1(A, D, C)
and R2 (D, B), then R1, R2 are in BCNF.
26
Boyce-codd Normal Form (BCNF)
Ex2: Is the following relation in BCNF?
R(A, B, C, D)
F= { AB ->CD; AC ->BD; C->B}
Above relation is in 3NF (no partial dependencies and
no transitive dependencies - the C->B: one key/prime
attribute determines another key/prime attribute)
2 Candidate keys is AB and AC
And FD: C->B, C is not a candidate key.
So the relation R violates BCNF. Thus, we break the
relation R into 2 relation R1 and R2, then R1, R2 are in
BCNF with R1(A, C, D), R2 (C,B)
27
Boyce-codd Normal Form (BCNF)
Ex3: Is the Student relation in BCNF?
With FDs:
31
32