Chapter 10 Functional Dependencies & Normalization
Chapter 10 Functional Dependencies & Normalization
Chapter 10
Functional Dependencies and
Normalization for Relational
Databases
١
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
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
٢
1 Informal Design Guidelines for
Relational Databases (1)
٣
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.
٤
1.2 Redundant Information in Tuples and
Update Anomalies
٥
EXAMPLE OF AN INSERT ANOMALY
٦
Figure 10.3 Two relation schemas
suffering from update anomalies
٧
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.
٨
1.4 Spurious Tuples
Bad designs for a relational database may result
in erroneous results for certain JOIN operations
The "lossless join" property is used to guarantee
meaningful results for join operations
GUIDELINE 4:
The relations should be designed to satisfy the
lossless join condition.
No spurious tuples should be generated by doing
a natural-join of any relations.
Note that:
Property (a) is extremely important and cannot be
sacrificed.
Property (b) is less stringent and may be sacrificed. (See
Chapter 11).
٩
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
١٠
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
١١
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
١٢
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
١٣
2.4 Minimal Sets of FDs (1)
A set of FDs is minimal if it satisfies the
following conditions:
1. Every dependency in F has a single attribute for
its RHS.
2. We cannot remove any dependency from F and
have a set of dependencies that is equivalent to
F.
3. We cannot replace any dependency X -> A in F
with a dependency Y -> A, where Y proper-
subset-of X ( Y subset-of X) and still have a set
of dependencies that is equivalent to F.
١٤
3 Normal Forms Based on Primary Keys
Normal form:
Condition using keys and FDs of a relation to
certify whether a relation schema is in a particular
normal form
١٥
Normalization of Relations (2)
2NF, 3NF, BCNF
based on keys and FDs of a relation 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)
١٦
3.3 Definitions of Keys and Attributes
Participating in Keys (1)
١٧
3.2 First Normal Form
Disallows
composite attributes
multivalued attributes
nested relations; attributes whose values for an
individual tuple are non-atomic
١٨
Figure 10.9 Normalization nested
relations into 1NF
١٩
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
٢٠
Figure 10.11 Normalization into 2NF and
3NF
٢١
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.
٢٢
4 General Normal Form Definitions (For
Multiple Keys) (1)
٢٣
5 BCNF (Boyce-Codd Normal Form)
A relation schema R is in Boyce-Codd Normal Form
(BCNF) if whenever an FD X -> A holds in R, then X is a
superkey of R
Each normal form is strictly stronger than the previous
one
Every 2NF relation is in 1NF
Every 3NF relation is in 2NF
Every BCNF relation is in 3NF
There exist relations that are in 3NF but not in BCNF
The goal is to have each relation in BCNF (or 3NF)
٢٤
Figure 10.13 a relation TEACH that is in
3NF but not in BCNF
٢٥
Achieving the BCNF by Decomposition (2)
Three possible decompositions for relation TEACH
{student, instructor} and {student, course}
Chapter Outline
Informal Design Guidelines for Relational
Databases
Functional Dependencies (FDs)
Definition, Inference Rules, Equivalence of Sets of
FDs, Minimal Sets of FDs
Normal Forms Based on Primary Keys
General Normal Form Definitions (For Multiple
Keys)
BCNF (Boyce-Codd Normal Form)
٢٦