8 Part A Relational Database Design
8 Part A Relational Database Design
• Normal form
It is a state of relation that results by applying simple
rules regarding functional dependencies (or relationships
between attributes) to that relation.
Types of Normal forms
• First normal form
• Second normal form
• Third normal form
• Boyce-Codd normal form
• Fourth normal form
• Fifth normal form
Functional Dependency
• A kind of Unique-value constraint.
• Knowledge of these constraints vital to eliminate
redundancy in database.
• An FD on a relation R is of the form X Y
(X functionally determines Y) where X, Y are sets of
attributes of R, such that whenever two tuples in R
have same values on all the attributes of X , they must
have same values on all the attributes of Y .
• Given X Y where Y is the set of all attributes of R
then X is a key for R.
Example FDs
• Consider the following relational schema
student_t(st_id, name, birth_date,
gender, hostel_no, room_no, sem,
year)
Example FDs
st_id name birth_date gender hostel_no room_no sem year
st_id st_name
course_no course_title
st_id course_no section_no, test_no, marks
RM2007022 111
RM2007022 222
RM2007025 333
RF2007023 444
RM2006011 555
RM2006014 666
RF2005073 777
RM2007022 111
Second normal form (2NF):
Functional dependency
Project table
Projno. Projtitle
10 tourism
30 Hospital
mgmt
25 RTO
Second normal form (2NF): Functional dependency
Student table
Rollno fname Class
RM2007022 Kunal SE
RM2007025 Tirth SE
RF2007023 Pooja SE
RM2006011 Yazad TE
RM2006014 Sahil TE
RF2005073 Pooja BE
RM2007022 Kunal SE
Second normal form (2NF): Functional dependency
Student-Project table
Projno. Rollno mks
10 RM2007022 25
10 RM2007025 25
10 RF2007023 25
30 RM2006011 50
30 RM2006014 50
Third Normal form(3NF): Transitive Dependency
RM2007022 Kunal SE 25
RM2007025 Tirth SE 25
RF2007023 Pooja SE 25
RM2006011 Yazad TE 50
RM2006014 Sahil TE 50
Rollno Class
RM2007022 SE
RF2007023 SE
SE 25
RM2006011 TE
TE 50
RM2006014 TE
BE 100
RF2005073 BE
Requirements: 1NF
• Each table has a primary key: minimal set of
attributes which can uniquely identify a record
48
Equivalence of FD sets
Defn. Two sets of FD’s, F and G, are equivalent if
their closures are equivalent, F + = G +
e.g., these two sets are equivalent:
{XY Z, X Y} and
{X Z, X Y}
49
Minimal Cover (Canonical Cover)
Defn. A FD set F is minimal if: we express
each FD in
1. Every FD in F is of the form X A,
simplest form
where A is a single attribute
2. For no X A in F is:
F – {X A } equivalent to F in a sense,
3. For no X A in F and Z X is: each FD is
“essential”
F – {X A } {Z A } equivalent to F
to the cover
Defn. F is a minimum cover for G if F is minimal and is equivalent to G.
e.g.,
{X Z, X Y} is a minimal cover for
{XY Z, X Z, X Y}
50
More on Closures
If F is a set of FD’s and X Y F +
then for some attribute A Y, X A F +
Proof by counterexample.
Assume otherwise and let Y = {A1,..., An}
Since we assume X A1, ..., X An are in F +
then X A1 ... An is in F + by union rule,
hence, X Y is in F + which is a contradiction
51
Why Armstrong’s Axioms?
Why are Armstrong’s axioms (or an equivalent rule
set) appropriate for FD’s? They are:
Consistent: any relation satisfying FD’s in F will satisfy those in F +
Complete: if an FD X Y cannot be derived by Armstrong’s axioms from
F, then there exists some relational instance satisfying F but not
XY
52
Proving Consistency
We prove that the axioms’ definitions must be true
for any instance, e.g.:
For augmentation (if X Y then XW YW):
53
Proving Completeness
Suppose X Y F + and define a relational instance
r that satisfies F + but not X Y:
Then for some attribute A Y, X A F +
X A X+ – X R – X+ – {A}
54
Proof of Completeness cont’d
Clearly this relation fails to satisfy X A and X Y.
We also have to check that it satisfies any FD in F + .
55
Normalize the following Relation
Student-course-professor details
Si Sn cid Cname Grad Cloc Se Pid pname
d am e c
e
1 X 31 Java A C1 1 P4 John
1 X 45 Oracle B C2 1 P6 David
5 Z 45 Oracle A C2 1 P6 David
Student details
Sid Sname
1 X
5 Z
Course details
31 Java C1
45 Oracle C2
Professor details
Pid pname
P4 John
P6 David
Student-course details
Sid cid Grade
1 31 A
1 45 B
5 45 A
Course-professor details
cid Sec Pid
31 1 P4
45 1 P6
BCNF(Boyce Codd Normal Form)
i.e;
If ABC and CB then
Decompose the table into relations having
columns (A,C) and (C,B).
Begin with the non-key FD StudIDStudName. This
results in the decomposition
EnrollProf(StudID,ClassID,Grade,ProfID) Stud(StudID,StudName)
Stud is BCNF, but EnrollProf is not. The FD
ClassIDProfID gives the further decomposition
Enroll(StudID,ClassID,Grade)
Prof(ClassID,ProfID)
Stud(StudID,StudName)
in which all schemas are BCNF.