Normalization: Relational Database Design
Normalization: Relational Database Design
com/c/EDULINEFORCSE
STUDENTS
MODULE 4
NORMALIZATION
ANOMALIES IN A DATABASE
• Consider the following relational schema pertaining to the
information about a student maintained by a university.
2. UPDATE ANOMALIES
• multiple copies of the same fact may lead to update anomalies or
inconsistencies when an update is made and only some of the multiple
copies are updated.
• Thus a change in the Phone_no of Jones must be made, for consistency,
in all tuples pertaining to the student Jones.
• If one of the three tuples of the figure is not changed to reflect the new
Phone_no of Jones, there will be an inconsistency in the data.
3. INSERTION ANOMALIES
• If this is the only relation in the database showing the association
between the faculty member and the course he or she teaches, the fact
that a given Professor is teaching a given Course cannot be entered in
the database unless a student is registered in the Course.
Prepared By Mr. EBIN PM, AP , CU EDULINE 5
4. DELETION ANOMALIES
• If the only student registered in a given Course discontinues the
course, the information as to which Professor is offering the course
will be lost if this is the only relation in the database showing the
association between a faculty member and the course she or he
teaches.
• If another relation in the database also establishes the relationship
between a Course and a Professor who teaches that course, the
deletion of the last tuple in “STDINF” for a given course will not
cause the information about the course’s teacher to be lost.
FUNCTIONAL DEPENDENCY
• Functional dependency (FD) is a set of constraints between two
attributes in a relation.
• It is basically a many-to-one relationship from one set of attributes
to another with in a given relational variable.
• Given two sets of attributes X and Y , Y is said to be functionally
dependent on X if a given value for each attribute in X uniquely
determines the value of the attribute in Y.(i.e., each X value is
associated with exactly one Y value.)
ARMSTRONG'S AXIOMS
• If F is a set of functional dependencies then the closure of F,
denoted as F+, is the set of all functional dependencies logically
implied by F (F = x→y).
• Armstrong's Axioms (Inference axioms) are a set of rules that,
when applied repeatedly, generates a closure of functional
dependencies.
PARTIAL DEPENDENCY
• Consider the relation R (name, course, grade, phone_ no, major,
course_dept).
• The functional dependencies are F {name→phone_no,major ;
course→course_dept ; name course→grade}.
• Name course is a candidate key. Name and course are prime
attributes. Grade is fully functionally dependent on the candidate
key. Phone_no, course_dept and major are partially dependent on
the candidate key.
Another example
• Given R (ABCD) and F {AB→C, B→D}, the key of this relation is AB
and D is partially dependent on the key.
Prepared By Mr. EBIN PM, AP EDULINE 15
TRANSITIVE DEPENDENCY
• Given R (ABCDE) and functional dependencies f {AB→C, B→D,
C→E}.
• AB is the key and E is transitively dependent on the key, since
AB→C→E.
unnormalized relation
Relation in 1NF
Relation in 2NF
• To bring this relation into third normal form, we break the relation
into two relations as follows:
Relation in 3NF
TEACHER_DETAILS:
STATE_COUNTRY:
Example:
• Consider relation R(A, B, C, D, E) and the FDs are given below
A -> BC,
CD -> E,
B -> D,
E -> A
• All possible candidate keys in above relation are {A, E, CD, BC}
• All attribute are on right sides of all functional dependencies are
prime.
Example:
A relation R(A,B,C,D) with FD set {A->BC} is decomposed into
R1(ABC) and R2(AD). This is lossless join decomposition because
• First rule holds true as Att(R1) ⋃ Att(R2)=(ABC) ⋃ (AD)= (ABCD) =
Att(R)
• Second rule holds true as Att(R1) ⋂ Att(R2) = (ABC) ⋂ (AD) ≠ Ø
• Third rule holds true as Att(R1) ⋂ Att(R2) = A is a key of R1(ABC)
because A->BC is given.
Question:
Consider a schema R(A,B,C,D) and functional dependencies A->B and
C->D. Then the decomposition of R into R1(AB) and R2(CD) is
A. dependency preserving and lossless join
B. lossless join but not dependency preserving
C. dependency preserving but not lossless join
D. not dependency preserving and not lossless join
Ans:
For lossless join decomposition, these three conditions must hold
true:
Example:
Consider R(A,B,C,D,E)
F:{A->B, BC->E, ED->A}
R is decomposed into R1(AB) and R2(ACDE). Check the
decomposition is lossy or lossless.
Step 3
Now let us insert symbol ‘a’ for A->B in second column, second row
R1 ∩ R2 = A
(A → BC)
this is a lossless-join decomposition.
Step-03:
• Compare the results of Step-01 and Step-02.
• If the functional dependencies of set F has determined all those
attributes that were determined by the functional dependencies of
set G, then it means F covers G.
• Thus, we conclude F covers G (F ⊇ G) otherwise not.
Case-02: Determining Whether G Covers F
Step-01:
• Take the functional dependencies of set F into consideration.
• For each functional dependency X → Y, find the closure of X using
the functional dependencies of set F.
Step-02:
• Take the functional dependencies of set F into consideration.
• For each functional dependency X → Y, find the closure of X using
the functional dependencies of set G.
Step-03:
• Compare the results of Step-01 and Step-02.
• If the functional dependencies of set G has determined all those
attributes that were determined by the functional dependencies of
set F, then it means G covers F.
• Thus, we conclude G covers F (G ⊇ F) otherwise not.
Example:
A relation R (A , C , D , E , H) is having two functional dependencies sets F
and G as shown-
Set F
A → C, AC → D, E → AD, E → H
Set G
A → CD, E → AH
Which of the following holds true?
(A) G ⊇ F
(B) F ⊇ G
(C) F = G
(D) All of the above
Prepared By Mr. EBIN PM, AP EDULINE 55
CANONICAL COVER
• The canonical cover is defined as a simplified and reduced version
of a given functional dependency.
• The canonical cover is free from all irrelevant functional
dependencies
• The closure of canonical cover is the same as that of a given set of
functional dependency
• The canonical cover is not unique because there may be more than
one canonical cover for a given set of functional dependency.
• It is called irreducible a set of functional dependencies.
Need
• Working with the set containing extraneous functional
dependencies increases the computation time.
• Therefore, the given set is reduced by eliminating the useless
functional dependencies.
• This reduces the computation time and working with the
irreducible set becomes easier.
Example:
Relational scheme R ( W , X , Y , Z ) and the FDs are
{ X → W , WZ → XY , Y → WXZ }. Write the irreducible equivalent
(canonical cover)for this set of functional dependencies.
Step-01:
• Write all the functional dependencies such that each contains
exactly one attribute on its right side.
X → W , WZ → X , WZ → Y, Y → W, Y → X, Y → Z
Step-02:
• Check the essentiality of each functional dependency one by one.
For X → W:
• Considering X → W, (X)+ = { X , W }
• Ignoring X → W, (X)+ = { X }
Now,
• Clearly, the two results are different.
• Thus, we conclude that X → W is essential and can not be
eliminated.
For WZ → X:
• Considering WZ → X, (WZ)+ = { W , X , Y , Z }
• Ignoring WZ → X, (WZ)+ = { W , X , Y , Z }
Now,
• Clearly, the two results are same.
• Thus, we conclude that WZ → X is non-essential and can be
eliminated.
• Eliminating WZ → X, our set of functional dependencies reduces to
X → W , WZ → Y, Y → W, Y → X, Y → Z
• Now, we will consider this reduced set in further checks.
Prepared By Mr. EBIN PM, AP EDULINE 63
For WZ → Y:
• Considering WZ → Y, (WZ)+ = { W , X , Y , Z }
• Ignoring WZ → Y, (WZ)+ = { W , Z }
Now,
• Clearly, the two results are different.
• Thus, we conclude that WZ → Y is essential and can not be
eliminated.
For Y → W:
• Considering Y → W, (Y)+ = { W , X , Y , Z }
• Ignoring Y → W, (Y)+ = { W , X , Y , Z }
Now,
• Clearly, the two results are same.
• Thus, we conclude that Y → W is non-essential and can be
eliminated.
• Eliminating Y → W, our set of functional dependencies reduces to
X → W , WZ → Y, Y → X, Y → Z
• Now, we will consider this reduced set in further checks.
For Y → X:
• Considering Y → X, (Y)+ = { W , X , Y , Z }
• Ignoring Y → X, (Y)+ = { Y , Z }
Now,
• Clearly, the two results are different.
• Thus, we conclude that Y → X is essential and can not be
eliminated.
For Y → Z:
• Considering Y → Z, (Y)+ = { W , X , Y , Z }
• Ignoring Y → Z, (Y)+ = { W , X , Y }
Now,
• Clearly, the two results are different.
• Thus, we conclude that Y → Z is essential and can not be
eliminated.
• From here, our essential functional dependencies are
X → W, WZ → Y, Y → X, Y → Z
Step-03:
• Consider the functional dependencies having more than one
attribute on their left side.
• Check if their left side can be reduced.
In our set,
• Only WZ → Y contains more than one attribute on its left side.
• Considering WZ → Y, (WZ)+ = { W , X , Y , Z }
Now,
• Consider all the possible subsets of WZ.
• Check if the closure result of any subset matches to the closure
result of WZ.
Prepared By Mr. EBIN PM, AP EDULINE 68
(W)+ = { W }
(Z)+ = { Z }
Clearly,
• None of the subsets have the same closure result same as that of
the entire left side.
• Thus, we conclude that we can not write WZ → Y as W → Y or Z →
Y.
• Thus, set of functional dependencies obtained in step-02 is the
canonical cover.
X → W, WZ → Y, Y → X, Y → Z