SS ZG518-L7
SS ZG518-L7
Hyderabad Campus
Dr.R.Gururaj
CS&IS Dept.
Database Design & Applications
(SS ZG 518)
BITS Pilani, Hyderabad Campus
Lecture Session-7
Functional Dependencies and Normal Forms (Ch.10 & 11)
Content
Introduction to Schema Refinement
Functional Dependencies
Inference Rules
Normalization
Normal Forms (1NF and 2NF)
3 NF and BCNF
Decomposition requirements
Lossless join decomposition
Dependency preserving decomposition
1 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus
A good database design practice is essential to develop
good relational schemas at logical level.
Good database design is needed for:
Clarity in understanding the database and
To formulate good queries
This is achieved by schema refinement.
Introduction to Database Design
2 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus
Functional Dependency is a constraint between two sets
of attributes from the database.
Function Dependency
Denoted by X Y between two sets of attributes in R,
and specifies a constraint on the possible tuples that can
form a relational instance r of R.
Values of Y component are determined by X component.
(or) Y is functionally dependent on X.
Functional Dependencies
3 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus
XY
Thus, X functionally determines Y in a relation schema R if
and only if whenever two tuples of r(R) agree on their X
values they must necessarily agree on their Y values, but
Y X is not true (need not be)
Ex: ssn ename; {ssn, pnumber} Hours
Note: FDs cannot be inferred. They should be defined by someone
who knows the semantics of the database very well.
4 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus
Dname Dnumber Mgrssn Mgrstartdate
Department {Dnumber Dname, Mgrssn,mgrstartdate}
Mgrstubdate}
Essn Pno Hours
Work_on {Essn, pno} Hours
Diagrammatic Notation
5 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus
Rule 1 (1R
1
): (Reflexing)
If X > Y then X Y otherwise non trivial
Rule 2 (1R
2
) (Argumentation)
X Y; then XZ YZ
Rule 3 (1R
3
) (Transitive)
X Y ; Y Z; Then X Z;
Rule 4 (IR
4
) (Decomposition or projective rule)
X YZ then X Y; & X Z;
Rule 5 (IR
5
) (union rule)
X A; X B ; then X AB
Rule 6 (IR
6
) (Pseudo transitive)
X Y ; WY Z; then WX Z;
We can find the closure F
+
of F, by repeated application of rules IR-1 to
IR-3. These rules are called as Armstrongs Inference rules.
Inference Rules for FDs
6 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus 7 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus
Normalization process is first proposed by
Raymond Boyce and Edgar Codd in 1972.
Normalization of data is the process of analyzing relation
schemas based on their FDs and PKs/Keys to achieve the
desirable properties of
(i)Minimal redundancy
(ii)Minimal anomalies
Normalization & Normal forms
8 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus
DId Dname Dloc
10 Engg HYD
CHENNAI
20 Mark HYD
MUMBAI
1. First Normal Form (INF)
It states that the domain of any attribute must include only
atomic (single / simple/ individual) values.
In the example given below, under the column Dloc each
row has more than on values.
Ex.: Dept
9 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus
2. Second Normal Form (2NF)
It is based on full functional dependency.
{X A} is fully functional if we remove any attribute from X then
that FD does not hold anymore.
Condition for 2NF: All non-key attributes are fully functionally dependent on
key (or) no non-key attribute should be dependent on part of key(partial
dependency).
eid pnum Hours ename ploc
10 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus 11 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus
Here, {ename} is a non key attribute and
determined by {eid} which is part of the key. Hence
we say that ename not fully functionally dependent
on key.
The relation shown is not in 2NF. Now we can
decompose this in to three relations as shown
below.
eid ename pnum ploc eid pnum hours
12 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus 13 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus
3. Third Normal form (3NF)
It is based on transitive dependency.
According to this, a relation should not have a non key attribute
functionally determined by another non key attribute. i.e., there should
be no transitive dependency.
eid address ename dnum dname dloc
Not in 3NF, because Dname is transitively dependent on eid.
14 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus
Now we can decompose the above into 2 relations.
eid address ename dnum Dnum Dname dloc
Condition for 3NF
For each FD, X A in database
i) X must be a superkey or
ii) A is key attribute
15 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus
BCNF (Boyce Codd Normal Form)
It is a stricter form of 3NF
Condition
For each FD X A
X must be a superkey
16 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus 17 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus 18 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus 19 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus 20 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus
As we have seen, decomposition (of a bigger relation R
into smaller ones), is a major step in the process of
normalization.
But during this activity of decomposition, we need to
make sure that the decomposition is lossless and
dependency preserving
Decomposition and Desirable properties
21 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus
1
( )
R
r r =
[ 2
( )
R
r
[
1
( )
R
r
[
Let C represent a set of constraints on the database. A decomposition
{R
1
, R
2
, R
3
,.R
4
} of a relation schema R is a lossless join
decomposition for R if all relation instances r on R that are legal under
C.
.= r
= projection of r on R
1
r relation instance in R
F = FDs on R
(or) {R} {R
1
, R
2
}
*
Loss-less join Decomposition
22 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus 23 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus
Test for Lossless join property
24 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus 25 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus
Given a set of dependencies F on R, the projection of F on R
i
denoted by
(where R
i
is a subset of R); is the set of FDs X Y in F
+
such that the
attributes in X Y are contained in R
i
.
( )
1 2
( ) ( ) ...., ( )
m
R R R
F F F F
+
+
H H H =
Then it is dependency preserving decomposition.
- is projection of F on R
1
.
1
( )
R
f H
Dependency Preserving Decomposition
26 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus 27 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj
BITS Pilani, Hyderabad Campus
Summary
Introduction to Database Design
Functional Dependencies and Inference Rules
Concepts in Normalization
Normal Forms (1NF,2NF,3 NF and BCNF)
Desirable properties of Decomposition
(requirements)
Lossless join decomposition and tests
Dependency preserving decomposition and tests
28 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj