Académique Documents
Professionnel Documents
Culture Documents
1
Normal forms & Normal tests
The normal form of relation schema is the
highest normal form satisfied by the
schema.
There are various normal forms and normal
tests namely,
First normal form, Second normal form,
Third normal form, Boyce-Codd normal form
and tests to verify whether a relation
schema is in a desired normal form.
2
First normal form (1NF)
A relation schema is said to be in first
normal form if all its attributes are atomic.
3
A schema which is not in first normal form
Dlocations is a
multi-valued attribute.
4
Conversion into first normal form
5
Conversion into first normal form
Alternative technique to decomposition also exists.
You may expand the primary key incorporating the
Multi-valued attribute into the primary key.
6
Conversion into first normal form
If maximum number of values of multi-valued
attribute is known then you may replace the
multi-valued attribute by a number of attributes.
In the example, instead of using Dlocations, you
may use three attributes, namely
Dlocation1, Dlocation2, Dlocation3
assuming that the maximum number of values of
Dlocations can be three.
This solution has the disadvantage of introducing NULL values if most
departments have fewer than three locations. It further introduces spurious
semantics about the ordering among the location values that is not
originally intended. Querying on this attribute becomes more difficult. 7
Multi-valued attribute replaced
DEPARTMENT
Dname Dnumber Dmgr_ssn Docation1 Dlocation2 Dlocation3
8
Conversion into first normal form
First normal form does not allow complex attribute too.
9
Conversion into first normal form
Decompose
10
Multiple multi-valued attributes
11
Second normal form (2NF)
12
Example
13
Decomposition into 2NF
14
Decomposition into 2NF
15
Decomposed relation schemas of EMP_PROJ
R1 R3
R4
16
Decomposition rule
If you want to decompose a relation R with
respect to a functional dependency X Y then
one of the relations will be R1 = X U Y and the
other will be R2 = R – Y.
17
Third normal form (3NF)
A relation schema R is said to be in third normal
form if
18
Example
Consider the relation schema
19
Decomposition
So decompose the schema with respect to
transitive dependency.
20
Boyce-Codd normal form (BCNF)
A relation schema is said to be in BCNF if
(i) it is third normal form and
(ii) key attribute does not depend on non-key
attribute.
FD1: AB C
FD2: C B
22
Exercise problem 1
Consider the following relation:
CAR_SALE(Car#, Date_sold, Salesperson#, Commission%,
Discount_amt).
Assume that a car may be sold by multiple
salespeople, and hence {Car#, Salesperson#} is
the primary key.
Additional dependencies are Date_sold → Discount_amt,
Salesperson# → Commission%.
Based on the given primary key, is this relation in 1NF, 2NF,
or 3NF? Why or why not? How would you successively
normalize it completely?
Ans. R1(Salesperson#, Commission%), R2(Date_sold, Discount_amt),
R3(Car#, Date_sold, Salesperson#)
23
Exercise problem 2
Consider the following relation for published books:
BOOK (Book_title, Author_name, Book_type, List_price,
Author_affil, Publisher).
Author_affil refers to the affiliation of author.
Suppose that the following dependencies exist:
Book_title → Publisher, Book_type
Book_type → List_price
Author_name → Author_affil.
24
Exercise problem 3
Consider the following relation:
CAR_SALE (Car_id, Option_type, Option_listprice, Sale_date,
Option_discountedprice).
This relation refers to options installed in cars (e.g., cruise control)
that were sold at a dealership, and the list and discounted prices of
the options.
25
Exercise problem 4
Consider the universal relation
R = {A, B, C, D, E}
and the set of functional dependencies
F = {ABC, ADE}.
What is the key for R? Decompose R into 2NF and
then 3NF relations.
Ans. Key = AB
D = {R1(A, D, E), R2(A, B, C)}
26
Exercise problem 4a
Consider the universal relation
R = {A, B, C, D, E, G, H, I, J, K}
and the set of functional dependencies
F = {ABC, ADE, BK, KGH, D IJ}.
What is the key for R? Decompose R into the
highest possible normal form.
Ans. Key: AB
D = {R1(A, D, E), R2(B, K), R3(A, B, C, G, H, I, J, K)}
27
Exercise problem 5
Consider the universal relation
R = {A, B, C, D, E, F, G, H, I, J, K}
and the set of functional dependencies
F = {AB C, BD EF, AD GH, A I, HJ}.
What is the key for R? Decompose R into the
highest possible normal form.
28
Exercise problem 6
Consider a relation R with five attributes ABCDE. You are
given the following dependencies:
A → B, BC → E, and ED → A.
i) List all keys for R.
ii) Is R in 3NF?
iii) Is R in BCNF?
Decompose the schema into the highest possible normal
form, if required.
29
Partial Solution 6
A+ = AB ≠ R
(BC)+ = BCE ≠ R
(ED)+ = EDAB ≠ R
(ABC)+ = ABCE ≠ R
(AED)+ = AEDB ≠ R
(BCED)+ = R so BCED is a super key of R
(CED)+ = CEDAB = R and (CE)+ ≠ R, (CD)+ ≠ R.
So CED is a key of R.
Similarly, show that BCD is also a key of R.
30
Exercise problem 6
Consider the attribute set R = ABCDEGH and the FD set
F = {AB → C, AC → B, AD → E, B → D, BC → A, E → G}.
i) List all keys for R.
ii) Is R in 3NF?
iii) Is R in BCNF?
Decompose the schema into the highest possible normal
form, if required.
31