3 NF
3 NF
3 NF
Functional Dependencies
Normal forms
How to assure certain form
condition by decomposing
relational model?
3.1.1 Definition of Functional Dependency
Corollary 1
A1A2…An → B1
A1A2…An → B2
…
A1A2…An → Bm
iff
A1A2…An → B1B2…Bm
Corollary 2
A→A
3.1.1 Definition of Functional Dependency
dependencies
Three cases of asserting functional
(Cont.)
2.If there are two tuples with the
same values in their A components
do not have the same values in B,
then A → B does not hold.
A B C D
a1 b1 c1 d1 C->A ?
a1 b2 c1 d2 BC->D ?
a2 b2 c2 d2
a2 b3 c2 d3
a3 b3 c2 d4
3.1.1 Definition of Functional Dependency
Key:
We say a set of one or more
attributes {A1, A2, ... ,An} is a key
for a relation if:
Those attributes functionally
determine all other attributes of the
relation. (superkey)
No proper subset of {A1,
A2, ... ,An} functionally determines
all other attributes of R. (minimal)
3.1.2 Keys of Relations
Candidate key:
All keys of a relation.
Primary key:
Sometimes a relation has more
than one key, and one of the
keys is designated as the
primary key.
3.1.3 Superkey
Superkeys:
Superset of a key.
A set of attributes that contains a key.
Those attributes functionally
determine all other attributes of the
relation.
The relationship between keys and
superkeys:
Keys are superkeys.
{title, year, starName} ?
Some superkeys are not keys.
{title, year, length, starName} ?
Exercise
Example: p90
If we are told that a relation R with
attributes A, B and C, satisfies the
functional dependencies A→B and B→C,
then we can deduce that R also
satisfies the dependency A→C.
Proof: Set (a,b1,c1) and (a,b2,c2) as the
tuples of R.
Since A→B, b1=b2
Since B→C, c1=c2
Then A→C
3.2.1 Reasoning About Functional Dependencies
Splitting/Combining Rule:
A1A2…An → B1B2…Bm
is a shorthand for A1A2…An → B1
A1A2…An → B2
…
A1A2…An → Bm
The trivial-dependency
rule: A C
the
We can remove from
right side of a
B
functional t
dependency those
attributes that appear
on the left. u
That is:
The functional
dependency If t and u Then they
A1A2...An→B1B2..Bm agree in must agree
is equivalent to the A’s in the B’s
A1A2...An→C1C2...Ck,
So surely they
where the C’s are all
those B’s that are not agree in the C’s
also A’s.
3.2.4 Computing the Closure of Attributes
Y+ X A
new Y+
3.2.4 Computing the Closure of Attributes
Example:
Let us consider a relation with
schema R(A,B,C,D,E,F) and a set of
functional dependencies
S: {BC→AD, AB→C, D→E, CF→B}
Please computer {A, B}+.
3.2.4 Computing the Closure of Attributes
Example:
Let us consider a relation with
schema R(A,B,C,D,E,F) and a set of
functional dependencies
S: {AB→C, BC→AD, D→E, CF→B}
Please test whether AB→D and
D→A follow from the dependencies
of S?
3.2.4 Computing the Closure of Attributes
Example: p80
Consider a relation with schema R
(A,B,C) and a set of dependencies
F: { A → B, A → C, B → A, B → C, C →
A, C → B }
Then the minimal bases are {A→B,
B→A, B→C, C→B}, {A→B, B→C, C→
A} and so on.
3.2.7 Closing Sets of Functional Dependencies
Armstrong’s axioms:
Reflexivity
If {B1,B2,…,Bm}{A1,A2,…,An}, then
A1A2…An→B1B2…Bm. ( trivial)
Augmentation
If A1A2…An→B1B2…Bm, then A1A2…
AnC1C2…C→B1B2…BmC1C2…Ck for any
set of attributes C1,C2,…,Ck.
Transitivity
If A1A2…An→B1B2…Bm and B1B2…
Bm→C1C2…Ck, then A1A2…An→C1C2…
Ck.
Example
R(A,B,C,D)
Consider a relation with schema
and functional dependencies
AB → C, C → D and D → A.
1. What are all the nontrivial functional
dependencies that follow from the
given dependencies?
2. What are all the keys of R?
3. What are all the superkeys for R that
are not keys?
4. Does B->C follow from the given FDs?
5. Does C->A follow from the given FDs?
3.3 Design of Relational Database Schemas
Causes of redundancy:
A fact is repeated in more than one
tuple.
The most common cause for the
redundancy: attempts to group into one
relation both single-value and multivalued
properties of an object.
title year length filmType studioName starName
Movies
Star Wars 1977 124 color Fox Carrie Fisher
Star Wars 1977 124 color Fox Mark Hamill
Star Wars 1977 124 color Fox Harrison Ford
Mighty Ducks 1991 104 color Disney Emilio Estevez
Wayne’s World 1992 95 color Paramount Dana Carvey
Wayne’s World 1992 95 color Paramount Mike Meyers
3.3 Design of Relational Database Schemas
Decomposing relations:
Given a relation R with schema
{A1,A2,...,An}, we may decompose R into
two relations S and T with schemas
{B1,B2,...,Bm} and {C1,C2,...,Ck}, such that
{A1,A2,...,An} =
{B1,B2,...,Bm}∪{C1,C2,...,Ck}.
The tuples in relation S are the projections
onto {B1,B2,...,Bm} of all the tuples in R.
The tuples in relation T are the projections
onto {C1,C2,...,Ck} of all the tuples in R.
3.3.2 Decomposing Relations
Projection:
For each tuple t in the current
instance of R, take the components
of t in the attributes B1, B2, ...,Bm.
Keep only one copy of each tuple.
3.3.2 Decomposing Relations
R in BCNF:
1) There is no nontrivial dependency
in R. (none but trivial dependency)
into
We can break any relation schema
a collection of subset of its
attributes with the following important
properties:
These subsets are the schemas of
relations in BCNF.
The data in the original relation is
represented faithfully by the data in
the relations that are the result of
the decomposition, that is, we need
to be able to reconstruct the original
relation exactly from the
decomposed relations.
3.3.4 Decomposition into BCNF
Decomposition strategy:
Algorithm:
Consider each set of attributes X
that is contained in the set of
attributes of S. Compute X+. Then
for each attribute B such that
B is an attribute of S,
B is in X+, and
B is not in X,
the functional dependency X→B
holds in S.
3.2.8 Projecting Functional Dependencies
Example:
Let R have schema R(A,B,C,D), and suppose
the functional dependencies A→B and B→C
are given for R.
Let S(A,C) be one of the relation in a
decomposition of R. Please compute the
dependencies that hold in S.
decomposition:
Three distinct properties of a
Elimination of anomalies.
Recoverability of information.
Preservation of dependencies.
3.4.1 Recovering Information from a Decomposition
Example: p95
If we decompose R
A B C
1 2 3
4 2 5
into
R1(A,B) R2(B,C)
A B B C
1 2 2 3
4 2 2 5
Reconstruct R by joining
A B C
1 2 3
1 2 5
4 2 3
4 2 5
3.4.4 Dependence Preservation
Decomposition strategy:
Attribute independence:
Two sets of attributes have no
relationship in a relation, and they
have sets of values that appear in
all possible combinations.
3.6.2 Definition of Multivalued Dependencies
with u on all t
|| ||
attributes of R v
that are not among || ||
Then A →→ B holds.
3.6.2 Definition of Multivalued Dependencies
Example:
department →→ class ?
class student
department
01 11 S1
01 11 S2
01 11 S3
01 12 S4
01 12 S5
3.6.3 Reasoning About Multivalued Dependencies
Transitive rule:
If A →→ B and B →→ C hold for
some relation, then A →→ C holds.
3.6.3 Reasoning About Multivalued Dependencies
Complementation rule:
If A →→ B for a relation R, then A
→→ C where C’s are all attributes
of R not among the A’s and B’s.
Example: name →→ street city
holds, then name →→ title year
holds.
3.6.3 Reasoning About Multivalued Dependencies
R in 4NF:
There is no nontrivial multivalued dependency
in R. (none but trivial multivalued dependency)
The left side of every nontrivial multivalued
dependency must contain a key.
Relations
in 1NF Atomicity
Relations
in 2NF
Relations
in 3NF
Functional dependencies
Relations
in BCNF
Relations
in 4NF Multivalued dependencies
3.6.6 Relationships Among Normal Forms