Copyright © 2007 Ramez Elmasri and Shamkant B.
Navathe Slide 10- 1
Chapter 10
Functional Dependencies and
Normalization for Relational
Databases
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Chapter Outline
1 Informal Design Guidelines for Relational Databases
1.1Semantics of the Relation Attributes
1.2 Redundant Information in Tuples and Update Anomalies
1.3 Null Values in Tuples
1.4 Spurious Tuples
2 Functional Dependencies (FDs)
2.1 Definition of FD
2.2 Inference Rules for FDs
2.3 Equivalence of Sets of FDs
2.4 Minimal Sets of FDs
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 3
Chapter Outline
3 Normal Forms Based on Primary Keys
3.1 Normalization of Relations
3.2 Practical Use of Normal Forms
3.3 Definitions of Keys and Attributes Participating in Keys
3.4 First Normal Form
3.5 Second Normal Form
3.6 Third Normal Form
4 General Normal Form Definitions (For Multiple Keys)
5 BCNF (Boyce-Codd Normal Form)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 4
1 Informal Design Guidelines for
Relational Databases (1)
What is relational database design?
The grouping of attributes to form "good" relation
schemas
Two levels of relation schemas
The logical "user view" level
The storage "base relation" level
Design is concerned mainly with base relations
What are the criteria for "good" base relations?
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 5
Informal Design Guidelines for Relational
Databases (2)
We first discuss informal guidelines for good relational
design
Then we discuss formal concepts of functional
dependencies and normal forms
- 1NF (First Normal Form)
- 2NF (Second Normal Form)
- 3NF (Third Normal Form)
- BCNF (Boyce-Codd Normal Form)
Additional types of dependencies, further normal forms,
relational design algorithms by synthesis are discussed in
Chapter 11
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 6
1.1 Semantics of the Relation Attributes
GUIDELINE 1: Informally, each tuple in a relation should
represent one entity or relationship instance. (Applies to
individual relations and their attributes).
Attributes of different entities (EMPLOYEEs,
DEPARTMENTs, PROJECTs) should not be mixed in the
same relation
Only foreign keys should be used to refer to other entities
Entity and relationship attributes should be kept apart as
much as possible.
Bottom Line: Design a schema that can be explained
easily relation by relation. The semantics of attributes
should be easy to interpret.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 7
Figure 10.1 A simplified COMPANY
relational database schema
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 8
1.2 Redundant Information in Tuples and
Update Anomalies
Information is stored redundantly
Wastes storage
Causes problems with update anomalies
Insertion anomalies
Deletion anomalies
Modification anomalies
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 9
EXAMPLE OF AN UPDATE ANOMALY
Consider the relation:
EMP_PROJ(Emp#, Proj#, Ename, Pname,
No_hours)
Update Anomaly:
Changing the name of project number P1 from
“Billing” to “Customer-Accounting” may cause this
update to be made for all 100 employees working
on project P1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 10
EXAMPLE OF AN INSERT ANOMALY
Consider the relation:
EMP_PROJ(Emp#, Proj#, Ename, Pname,
No_hours)
Insert Anomaly:
Cannot insert a project unless an employee is
assigned to it.
Conversely
Cannot insert an employee unless an he/she is
assigned to a project.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 11
EXAMPLE OF AN DELETE ANOMALY
Consider the relation:
EMP_PROJ(Emp#, Proj#, Ename, Pname,
No_hours)
Delete Anomaly:
When a project is deleted, it will result in deleting
all the employees who work on that project.
Alternately, if an employee is the sole employee
on a project, deleting that employee would result in
deleting the corresponding project.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 12
Figure 10.3 Two relation schemas
suffering from update anomalies
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 13
Figure 10.4 Example States for
EMP_DEPT and EMP_PROJ
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 14
Guideline to Redundant Information in
Tuples and Update Anomalies
GUIDELINE 2:
Design a schema that does not suffer from the
insertion, deletion and update anomalies.
If there are any anomalies present, then note them
so that applications can be made to take them into
account.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 15
1.3 Null Values in Tuples
GUIDELINE 3:
Relations should be designed such that their
tuples will have as few NULL values as possible
Attributes that are NULL frequently could be
placed in separate relations (with the primary key)
Reasons for nulls:
Attribute not applicable or invalid(Student Visa
Status)
Attribute value unknown (may exist) (Emp DOB)
Value known to exist, but unavailable (Phone No)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 16
2.1 Functional Dependencies (1)
Functional dependencies (FDs)
Are used to specify formal measures of the
"goodness" of relational designs
And keys are used to define normal forms for
relations
Are constraints that are derived from the meaning
and interrelationships of the data attributes
A set of attributes X functionally determines a set
of attributes Y if the value of X determines a
unique value for Y
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 17
Functional Dependencies (2)
Written as X -> Y; can be displayed graphically on a
relation schema
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 18
Examples of FD constraints (1)
Social security number determines employee
name
SSN -> ENAME
Project number determines project name and
location
PNUMBER -> {PNAME, PLOCATION}
Employee ssn and project number determines the
hours per week that the employee works on the
project
{SSN, PNUMBER} -> HOURS
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 19
Examples of FD constraints (2)
An FD is a property of the attributes in the
schema R
The constraint must hold on every relation
instance r(R)
If K is a key of R, then K functionally determines
all attributes in R
(since we never have two distinct tuples with
t1[K]=t2[K])
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 20
2.2 Inference Rules for FDs (1)
Given a set of FDs F, we can infer additional FDs that
hold whenever the FDs in F hold
Armstrong's inference rules:
IR1. (Reflexive) If Y subset-of X, then X -> Y
IR2. (Augmentation) If X -> Y, then XZ -> YZ
(Notation: XZ stands for X U Z)
IR3. (Transitive) If X -> Y and Y -> Z, then X -> Z
IR1, IR2, IR3 form a sound and complete set of
inference rules
These rules hold and all other rules that hold can be
deduced from these
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 21
Inference Rules for FDs (2)
Some additional inference rules that are useful:
Decomposition: If X -> YZ, then X -> Y and X ->
Z
Union: If X -> Y and X -> Z, then X -> YZ
Psuedotransitivity: If X -> Y and WY -> Z, then
WX -> Z
The last three inference rules, as well as any
other inference rules, can be deduced from IR1,
IR2, and IR3 (completeness property)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 22
Inference Rules for FDs (3)
Closure of a set F of FDs is the set F+ of all FDs
that can be inferred from F
Closure of a set of attributes X with respect to F
is the set X+ of all attributes that are functionally
determined by X
X+ can be calculated by repeatedly applying IR1,
IR2, IR3 using the FDs in F
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 23
Example
Let we specify the following set F of functional
dependencies that should hold on EMP_PROJ:
F = {SSN->ENAME,
PNUMBER->{PNAME, PLOCATION},
{SSN, PNUMBER}->HOURS}
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 24
Example (Cont..)
we calculate the following closure sets with
respect to F:
{ SSN }+ = { SSN, ENAME }
{ PNUMBER }+ = { PNUMBER, PNAME,
PLOCATION }
{ SSN, PNUMBER }+ = { SSN, PNUMBER,
HOURS }
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 25
Example (Cont..)
Functional Dependency set
{ STUD_NO->STUD_NAME,
STUD_NO->STUD_PHONE,
STUD_NO->STUD_STATE,
STUD_NO->STUD_COUNTRY,
STUD_NO -> STUD_AGE,
STUD_STATE->STUD_COUNTRY }
Closure Set
(STUD_NO)+ = {STUD_NO, STUD_NAME, STUD_PHONE,
STUD_STATE, STUD_COUNTRY, STUD_AGE}
(STUD_STATE)+ = {STUD_STATE, STUD_COUNTRY}
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 26
Full Functional Dependency
Full Functional Dependency:
Only of relevance with composite determinants.
This is the situation when it is necessary to use all the
attributes of the composite determinant to identify its object
uniquely.
Full Functional Dependencies
order# line# qty price (Order#, line#) qty
(Order#, line#) price
A001 001 10 200
A002 001 20 400
A002 002 25 800
A004 001 15 300
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 27
Partial Functional Dependency
Partial Functional Dependency:
This is the situation that exists if it is necessary to only use
a subset of the attributes of the composite determinant to
identify its object uniquely.
Example: Full Functional Dependencies
student# unit# room grade (student#, unit#) grade
9900100 A01 TH224 2
9900010 A01 TH224 14
9901011 A02 JS075 3 Partial Functional Dependencies
9900001 A01 TH224 16 unit# room
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 28
Functional Dependency: Exercise
Abbreviations Meaning
A Employee no
B Dept no
C Manager’s emp no
D Proj no directed by that manager
E Dept name
F Time allocated to specified proj
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 29
Functional Dependency: Exercise
Abbreviations Meaning
A BC Employee no Deptno,
Manager’s emp no
BE Dept no Dept name
CD EF Manager’s emp no, Proj no
directed by that manager
Dept name, Time allocated to
specified proj
We now show that FD (AD F) holds in R
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 30
Solution
As A BC (given)
So, A C (1, decomposition)
And AD CD (2, augmentation)
Similarly, as CD EF (given)
So AD EF (3 and 4, transitivity)
Hence, AD F (5, decomposition)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 31
Functional Dependency
Example:
staffNo job dept dname
SL10 Salesman 10 Sales
SA51 Manager 20 Accounts
DS40 Clerk 20 Accounts
OS45 Clerk 30 Operations
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Functional Dependency
Example:
staffNo job dept dname
SL10 Salesman 10 Sales
SA51 Manager 20 Accounts
DS40 Clerk 20 Accounts
OS45 Clerk 30 Operations
Functional Dependencies
staffNo job
staffNo dept
staffNo dname
dept dname
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Steps in normalization
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
3 Normal Forms Based on Primary Keys
3.1 Normalization of Relations
3.2 Practical Use of Normal Forms
3.3 Definitions of Keys and Attributes
Participating in Keys
3.4 First Normal Form
3.5 Second Normal Form
3.6 Third Normal Form
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 35
3.1 Normalization of Relations (1)
Normalization:
The process of decomposing unsatisfactory "bad"
relations by breaking up their attributes into
smaller relations
Normal form:
Condition using keys and FDs of a relation to
certify whether a relational schema is in a
particular normal form
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 36
Normalization of Relations (2)
2NF, 3NF, BCNF
based on keys and FDs of a relational schema
4NF
based on keys, multi-valued dependencies :
MVDs; 5NF based on keys, join dependencies :
JDs (Chapter 11)
Additional properties may be needed to ensure a
good relational design (lossless join, dependency
preservation; Chapter 11)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 37
3.2 Practical Use of Normal Forms
Normalization is carried out in practice so that the
resulting designs are of high quality and meet the
desirable properties
The practical utility of these normal forms becomes
questionable when the constraints on which they are
based are hard to understand or to detect
The database designers need not normalize to the highest
possible normal form
(usually up to 3NF, BCNF or 4NF)
Denormalization:
The process of storing the join of higher normal form
relations as a base relation—which is in a lower normal form
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 38
3.2 First Normal Form
Disallows
composite attributes
multivalued attributes
nested relations; attributes whose values for an
individual tuple are non-atomic
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 39
Figure 10.8 Normalization into 1NF
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 40
Figure 10.9 Normalization nested
relations into 1NF
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 41
Another Example: Bringing a
Relation to 1NF
Option 1: Make a determinant of the repeating group (or
the multivalued attribute) a part of the primary key.
Composite
Primary
Key
STUDENT
Stud_ID Name Course_ID Units
101 Lennon MSI 250 3.00
101 Lennon MSI 415 3.00
125 Johnson MSI 331 3.00
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 42
Another Example: Bringing a
Relation to 1NF
Option 2: Remove the entire repeating group from
the relation.
Create another relation which would contain all the attributes of
the repeating group, plus the primary key from the first relation.
In this new relation, the primary key from the original relation
and the determinant of the repeating group will comprise a
primary key.
STUDENT
Stud_ID Name Course_ID Units
101 Lennon MSI 250 3.00
101 Lennon MSI 415 3.00
125 Johnson MSI 331 3.00
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 43
Another Example: Bringing a
Relation to 1NF
STUDENT
Stud_ID Name
101 Lennon
125 Jonson
STUDENT_COURSE
Stud_ID Course Units
101 MSI 250 3
101 MSI 415 3
125 MSI 331 3
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 44
3.3 Second Normal Form (1)
Uses the concepts of FDs, primary key
Definitions
Prime attribute: An attribute that is member of the primary
key K
Full functional dependency: a FD Y -> Z where removal
of any attribute from Y means the FD does not hold any
more
Examples:
{SSN, PNUMBER} -> HOURS is a full FD since neither SSN
-> HOURS nor PNUMBER -> HOURS hold
{SSN, PNUMBER} -> ENAME is not a full FD (it is called a
partial dependency ) since SSN -> ENAME also holds
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 45
Second Normal Form (2)
A relation schema R is in second normal form
(2NF) if every non-prime attribute A in R is fully
functionally dependent on the primary key
R can be decomposed into 2NF relations via the
process of 2NF normalization
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 46
Bringing a Relation to 2NF
Composite
Primary
Key
STUDENT
Stud_ID Name Course_ID Units
101 Lennon MSI 250 3.00
101 Lennon MSI 415 3.00
125 Johnson MSI 331 3.00
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 47
Bringing a Relation to 2NF
Goal: Remove Partial Dependencies
Composite Partial
Primary Dependencies
Key
STUDENT
Stud_ID Name Course_ID Units
101 Lennon MSI 250 3.00
101 Lennon MSI 415 3.00
125 Johnson MSI 331 3.00
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 48
Bringing a Relation to 2NF
Remove attributes that are dependent from the part but not the
whole of the primary key from the original relation.
For each partial dependency, create a new relation, with the
corresponding part of the primary key from the original as the
primary key.
STUDENT
Stud_ID Name Course_ID Units
101 Lennon MSI 250 3.00
101 Lennon MSI 415 3.00
125 Johnson MSI 331 3.00
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 49
Bringing a Relation to 2NF
STUDENT_COURSE
Student
Stud_ID Course_ID
Stud_ID Name Course_ID Units 101 MSI 250
101 Lennon MSI 250 3.00
101 Lennon MSI 415 3.00
101 MSI 415
125 Johnson MSI 331 3.00
125 MSI 331
STUDENT COURSE
Stud_ID Name Course_ID Units
101 Lennon MSI 250 3.00
101 Lennon MSI 415 3.00
125 Johnson MSI 331 3.00
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 50
3.4 Third Normal Form (1)
Definition:
Transitive functional dependency: a FD X -> Z
that can be derived from two FDs X -> Y and Y ->
Z
Examples:
SSN -> DMGRSSN is a transitive FD
Since SSN -> DNUMBER and DNUMBER ->
DMGRSSN hold
SSN -> ENAME is non-transitive
Since there is no set of attributes X where SSN -> X
and X -> ENAME
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 51
Third Normal Form (2)
A relation schema R is in third normal form (3NF) if it is
in 2NF and no non-prime attribute A in R is transitively
dependent on the primary key
R can be decomposed into 3NF relations via the process
of 3NF normalization
NOTE:
In X -> Y and Y -> Z, with X as the primary key, we consider
this a problem only if Y is not a candidate key.
When Y is a candidate key, there is no problem with the
transitive dependency .
E.g., Consider EMP (SSN, Emp#, Salary ).
Here, SSN -> Emp# -> Salary and Emp# is a candidate key.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 52
Bringing a Relation to 3NF
Goal: Get rid of transitive dependencies.
Transitive
Dependency
EMPLOYEE
Emp_ID F_Name L_Name Dept_ID Dept_Name
111 Mary Jones 1 Acct
122 Sarah Smith 2 Mktg
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 53
Bringing a Relation to 3NF
Remove the attributes, which are dependent on a non-key attribute, from the original
relation.
For each transitive dependency,
create a new relation with the non-key attribute which is a determinant in
the transitive dependency as a primary key,
and the dependent non-key attribute as a dependent.
EMPLOYEE
Emp_ID F_Name L_Name Dept_ID Dept_Name
111 Mary Jones 1 Acct
122 Sarah Smith 2 Mktg
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 54
Bringing a Relation to 3NF
EMPLOYEE
Emp_ID F_Name L_Name Dept_ID Dept_Name
111 Mary Jones 1 Acct
122 Sarah Smith 2 Mktg
EMPLOYEE
Emp_ID F_Name L_Name Dept_ID
111 Mary Jones 1
122 Sarah Smith 2
DEPARTMENT
Dept_ID Dept_Name
1 Acct
2 Mktg
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 55
Example
Primary Key (Supplier#, Part#)
S# Status City P# Qty
S1 20 London P1 1600
S1 20 London P2 2000
S2 10 Paris P2 500
S3 20 London P3 3000
Insert - cannot insert the fact that a supplier is located in a
particular city until supplier supplies at least one part
Delete - delete the value P3, and we also lose the information
that S3 is located in London
Update - S1 appears in the table more than once, and we must
change all of them -- Possibility of producing an inconsistent
result.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Example
By analyzing a given relation, we can identify some
dependencies between its attributes.
In principle, we want to make attributes independent of
each other as far as possible, so that updating one attribute
will have no impact on the others.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
2NF Example
FIRST {S#, STATUS, CITY, P#, QTY}
Primary key: {S#, P#}
{S#} -> {CITY}, {CITY} -> {STATUS}
Test of 2NF
{S#} -> {STATUS, CITY}: partial dependencies.
FIRST is in 1NF, but not in 2NF.
Decomposition:
SECOND {S#, STATUS, CITY}
SP {S# (FK: references SECOND), P#, QTY}
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
2NF-Solution to Problems
The solution is to replace the relation by two new
relations (called One and Two)
One: Primary Key (Supplier#) Two: Primary Key (Supplier#, Part#)
Supplier# Status City Supplier# Part# Quantity
S1 20 London S1 P1 1600
S2 10 Paris S1 P2 2000
S3 20 London S2 P2 500
S3 P3 3000
This revised structure overcomes all the problems sketched earlier, but:
• Insert - cannot insert the fact that a particular city has a status until a
supplier is actually located in that city.
• Delete - delete the value S2, and we also lose the information that
Paris has the status value 10.
• Update - Status value 20 appears in the table more than once.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Third Normal Form (3NF)
A table is in 3NF if and only if
it is in 2NF and
every non-key attribute is non-transitively dependent
on the primary key.
3NF prohibits transitive dependencies.
If A -> B and B -> C, C is transitively dependent
on A.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
3NF Example
SECOND {S#, STATUS, CITY}
Primary key: {S#}
{S#} -> {CITY}, {CITY} -> {STATUS}
Test of 3NF:
{S#} -> {CITY} -> {STATUS}: transitive dependency
SECOND is in 2NF, but not 3NF.
Decomposition:
CS {CITY, STATUS}
SC {S#, CITY (FK: references CS)}
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Third Normal Form (3NF)
A relation is in 3NF if and only if it is 2NF and all non-
key fields are mutually independent.
One: Primary Key (Supplier#) Two: Primary Key (Supplier#, Part#)
Supplier# Status City Supplier# Part# Quantity
S1 20 London S1 P1 1600
S2 10 Paris S1 P2 2000
S3 20 London S2 P2 500
S3 P3 3000
Note: Relation Two is in 3NF (with only one non-key field),
but relation One is not in 3NF because Status is dependent
on City (both are non-key fields)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
3NF - Converting 2NF into 3NF
We can now normalize relation One into two new relations
(called three and four), which both are in 3NF.
Three: Primary Key (Supplier#)
Four: Primary Key (City)
Supplier# City
S1 London City Status
London 20
S2 Paris
Paris 10
S3 London
Higher Normal Forms (e.g. 4NF and 5NF) do exist,
but they are mainly of interest in academic societies
rather than in the practical applications of database
design.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Normal Forms Defined Informally
1st normal form
All attributes depend on the key
2nd normal form
All attributes depend on the whole key
3rd normal form
All attributes depend on nothing but the key
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 64
Stages of Normalisation
Unnormalised
(UDF) Remove repeating groups
First normal form
(1NF) Remove partial dependencies
Second normal form
(2NF) Remove transitive dependencies
Third normal form
(3NF)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Example 2: University Database
Table
StdSSN StdClass StdCity OfferNo OffYear Offterm EnrGrade CourseNo CrsDesc
S1 JUN ISB O1 2003 1 3.5 C1 DB
S1 JUN ISB O2 2003 2 3.3 C2 VB
S2 JUN ISB O3 2003 1 3.1 C3 OO
S2 JUN ISB O2 2003 1 3.4 C2 VB
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Example 2: University Database
Table
StdSSN StdClass StdCity OfferNo OffYear Offterm EnrGrade CourseNo CrsDesc
S1 JUN ISB O1 2003 1 3.5 C1 DB
S1 JUN ISB O2 2003 2 3.3 C2 VB
S2 JUN ISB O3 2003 1 3.1 C3 OO
S2 JUN ISB O2 2003 1 3.4 C2 VB
StdSSN StdCity, StdClass
OfferNo OffTerm, OffYear, CourseNo, CrsDesc
CourseNo CrsDesc
StdSSN, OfferNo EnrGrade
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Problems
Anomalies:
- PK: combination of StdSSN and OfferNo
- Insert: cannot insert a new student without enrolling in an
offering (OfferNo part of PK)
- Update: change a course description; change every
enrollment of the course
- Delete: remove third row; lose information about course C3
Table has obvious redundancies
Easier to query: no joins
More difficult to change: can work around problems
(dummy PK) but tedious to do
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
FD Diagrams and Lists
StdSSN StdCity StdClass OfferNo OffTerm OffYear CourseNo CrsDesc EnrGrade
StdSSN StdCity, StdClass
OfferNo OffTerm, OffYear, CourseNo, CrsDesc
CourseNo CrsDesc
StdSSN, OfferNo EnrGrade
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Normalization
Process of removing unwanted redundancies
Apply normal forms
Identify FDs
Determine whether FDs meet normal form
Split the table to meet the normal form if there is a
violation
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
1NF
No repeating groups: flat rows
StdSSN StdClass OfferNo OffYear EnrGrade CourseNo CrsDesc
S1 JUN O1 2003 3.5 C1 DB
O2 2003 3.3 C2 VB
S2 JUN O3 2003 3.1 C3 OO
O2 2003 3.4 C2 VB
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Combined Definition of 2NF/3NF
Key column: candidate key or part of candidate
key
Analogy to the traditional justice oath
Every non key depends on a key, the whole key,
and nothing but the key
Usually taught as separate definitions
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
2NF
Every nonkey column depends on a whole key,
not part of a key
Violations
Part of key nonkey
Violations only for combined keys
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
2NF Example
Many violations for the big university
database table
StdSSN StdCity, StdClass
OfferNo OffTerm, OffYear, CourseNo,
CrsDesc
Splitting the table
UnivTable1 (StdSSN, StdCity, StdClass)
UnivTable2 (OfferNo, OffTerm, OffYear,
CourseNo, CrsDesc)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
3NF
Every nonkey column depends only on a key not
on non key columns
Violations: Nonkey Nonkey
Alterative formulation
No transitive FDs
A B, B C then A C
OfferNo CourseNo, CourseNo CrsDesc then
OfferNo CrsDesc
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
3NF Example
One violation in UnivTable2
CourseNo CrsDesc
Splitting the table
UnivTable2-1 (OfferNo, OffTerm, OffYear,
CourseNo)
UnivTable2-2 (CourseNo, CrsDesc)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Example 2
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Unnormalised Normal Form (UNF)
ORDER
Customer No: 001964 Order Number: 00012345
Name: Mark Campbell Order Date: 14-Feb-2002
Address: 1 The House
Leytonstone
E11 9ZZ
Product Product Unit Order Line
Number Description Price Quantity Total
T5060 Hook 5.00 5 25.00
PT42 Bolt 2.50 10 20.50
QZE48 Spanner 20.00 1 20.00
Order Total: 65.50
ORDER (order-no, order-date, cust-no, cust-name, cust-add,
(prod-no, prod-desc, unit-price, ord-qty, line-total)*, order-total
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
First Normal Form (1NF)
Definition: A relation is in 1NF if, and only if, all its
underlying attributes contain atomic values only.
Remove repeating groups into a new relation
A repeating group is shown by a pair of brackets within the
relational schema.
ORDER (order-no, order-date, cust-no, cust-name, cust-add,
(prod-no, prod-desc, unit-price, ord-qty, line-total)*, order-total
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Steps from UNF to 1NF:
Remove the outermost repeating group (and any
nested repeated groups it may contain) and create
a new relation to contain it.
Add to this relation a copy of the PK of the relation
immediately enclosing it.
Name the new entity (appending the number 1 to
indicate 1NF)
Determine the PK of the new entity
Repeat steps until no more repeating groups.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Example - UNF to 1NF
ORDER (order-no, order-date, cust-no, cust-name, cust-add,
(prod-no, prod-desc, unit-price, ord-qty, line-total)*, order-total
1. Remove the outermost repeating group (and any nested repeated
groups it may contain) and create a new relation to contain it.
ORDER-1
(rename (order-no,
original to indicateorder-date,
1NF) cust-no, cust-name, cust-add, order-total
(prod-no, prod-desc, unit-price, ord-qty, line-total)
2. Add to this relation a copy of the PK of the relation immediately enclosing it.
ORDER-1 (order-no, order-date, cust-no, cust-name, cust-add, order-total
(order-no, prod-no, prod-desc, unit-price, ord-qty, line-total)
3. Name the new entity (appending the number 1 to indicate 1NF)
ORDER-LINE-1 (order-no, prod-no, prod-desc, unit-price, ord-qty, line-total)
4. Determine the PK of the new entity
ORDER-LINE-1 (order-no, prod-no, prod-desc, unit-price, ord-qty, line-total)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Second Normal Form (2NF)
Definition: A relation is in 2NF if, and only if, it is in 1NF and
every non-key attribute is fully dependent on the primary key.
Remove partial functional dependencies into a new relation
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Steps from 1NF to 2NF:
Remove the offending attributes that are only
partially functionally dependent on the composite
key, and place them in a new relation.
Add to this relation a copy of the attribute(s) which
are the determinants of these offending attributes.
These will automatically become the primary key of
this new relation.
Name the new entity (appending the number 2 to indicate
2NF)
Rename the original entity (ending with a 2 to indicate
2NF)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Example - 1NF to 2NF
ORDER-LINE-1 (order-no, prod-no, prod-desc, unit-price, ord-qty, line-total)
1. Remove the offending attributes that are only partially functionally dependent on the
composite key, and place them in a new relation.
ORDER-LINE-1 (order-no, prod-no, ord-qty, line-total)
(prod-desc, unit-price)
2. Add to this relation a copy of the attribute(s) which determines these offending
attributes. These will automatically become the primary key of this new relation..
ORDER-LINE-1 (order-no, prod-no, ord-qty, line-total)
(prod-no, prod-desc, unit-price)
3. Name the new entity (appending the number 2 to indicate 2NF)
PRODUCT-2 (prod-no, prod-desc, unit-price)
4. Rename the original entity (ending with a 2 to indicate 2NF)
ORDER-LINE-2 (order-no, prod-no, ord-qty, line-total)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Third Normal Form (3NF)
Definition: A relation is in 3NF if, and only if, it is in 2NF and
every non-key attribute is non-transitively dependent on the
primary key.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Steps from 2NF to 3NF:
Remove the offending attributes that are transitively dependent on
non-key attribute(s), and place them in a new relation.
Add to this relation a copy of the attribute(s) which are the
determinants of these offending attributes. These will automatically
become the primary key of this new relation.
Name the new entity (appending the number 3 to indicate 3NF)
Rename the original entity (ending with a 3 to indicate 3NF)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Example - 2NF to 3NF
ORDER-2 (order-no, order-date, cust-no, cust-name, cust-add, order-total
1. Remove the offending attributes that are transitively dependent on non-key attributes,
and place them in a new relation.
ORDER-2 (order-no, order-date, cust-no, order-total
(cust-name, cust-add )
2. Add to this relation a copy of the attribute(s) which determines these offending
attributes. These will automatically become the primary key of this new relation..
ORDER-2 (order-no, order-date, cust-no, order-total
(cust-no, cust-name, cust-add )
3. Name the new entity (appending the number 3 to indicate 3NF)
CUSTOMER-3 (cust-no, cust-name, cust-add )
4. Rename the original entity (ending with a 3 to indicate 3NF)
ORDER-3 (order-no, order-date, cust-no, order-total
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Example - Relations in 3NF
ORDER-3 (order-no, order-date, cust-no, order-total
CUSTOMER-3 (cust-no, cust-name, cust-add )
PRODUCT-2 (prod-no, prod-desc, unit-price)
ORDER-LINE-2 (order-no, prod-no, ord-qty, line-total)
order-no prod-no
ORDER PRODUCT
shows
places placed by contains belongs to
cust-no order-no, prod-no
CUSTOMER
part of ORDER-LINE
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Reference
Chapter # 14
Fundamentals of database systems
7th Edition
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 10- 89