Unit-4 Relational Database Design
Unit-4 Relational Database Design
Relational
Database
Design
What is Functional Dependency?
The concept of FD is given by E.F.Codd which is also called
normalization process.
Goal of FD
Student
RollNo Name SPI BL
101 Raj 8 0
102 Meet 7 1
103 Suresh 7 1
104 Raj 8 0
What is Functional Dependency?
Let attributes X and Y are two subsets of attributes of relation R.
If the values of the X component of a tuple uniquely (or
functionally) determine the values of the Y component, then
there is a functional dependency from X to Y.
This is denoted by X → Y (i.e RollNo → Name, SPI, BL).
It is referred as: Y is functionally dependent on the X or X
functionally determines Y.
The abbreviation for functional dependency is FD or fd.
The set of attributes X is called the left hand side of the FD, and Y
is called the right hand side.
The left hand side of the FD is also referred as determinant
whereas the right hand side of the FD is referred as dependent.
Diagrammatic representation
X→Y {X1, X2} → Y X → {Y1, Y2}
X Y X1 X2 Y X Y1 Y2
Example
Consider the relation Account(account_no, balance, branch).
account_no can determine balance and branch.
So, there is a functional dependency from account_no to
balance and branch.
This can be denoted by account_no → {balance, branch}.
We have
A→B
Transitivity rule A→H
B→H
Example of closure of a set of FDs
Suppose we are given a relation schema R(A,B,C,G,H,I) and the
set of functional dependencies are:
• F = (A → B, A → C, CG → H, CG → I, B → H)
The functional dependency CG → HI is logical implied. ?
We have
CG → H
Union rule CG → HI
CG → I
Example of closure of a set of FDs
Suppose we are given a relation schema R(A,B,C,G,H,I) and the
set of functional dependencies are:
• F = (A → B, A → C, CG → H, CG → I, B → H)
The functional dependency AG → I is logical implied. ?
We have
A→C
Pseudo-transitivity rule AG → I
CG → I
Example of closure of a set of FDs
Suppose we are given a relation schema R(A,B,C,G,H,I) and the
set of functional dependencies are:
• F = (A → B, A → C, CG → H, CG → I, B → H)
The functional dependency AG → I is logical implied. ?
We have
A→C Augmentation rule AG → CG
AG → CG
Transitivity rule AG → I
CG → I
Decomposition
What is decomposition?
Decomposition is the process of breaking down
given relation into two or more relations.
Relation R is replaced by two or more relations in
such a way that:
1. Each new relation contains a subset of the attributes of R
2. Together, they all include all tuples and attributes of R
Types of decomposition
1. Lossy decomposition
2. Lossless decomposition (non-loss decomposition)
Lossy decomposition
The decomposition of relation R into R1 and R2 is
lossy when the join of R1 and R2 does not yield the
same relation as in R.
This is also referred as lossy-join decomposition.
The disadvantage of such kind of decomposition is
that some information is lost during retrieval of
original relation.
From practical point of view, decomposition should
not be lossy decomposition.
Lossy decomposition
Ano Balance Bname
A01 5000 Rajkot
A02 5000 Surat
Update Anomaly
An update anomaly exists when one or more records of duplicated data is updated,
but not all.
Normalization
Normalization
Different type of anomalies in database design can be solved
by using normalization.
It is step by step decomposition of complex records into simple
record.
What is normalization?
Normalization is the process of removing redundant
data from tables to improve data integrity,
scalability and storage efficiency.
1. Data Integrity (completeness, accuracy and consistency of data)
2. Scalability (ability of a system to continue to function well in a
growing amount of work)
3. Storage Efficiency (ability to store and manage data that
consumes the least amount of space)
Solution: Split the table into two tables in such as way that
• the first table contains all attributes except multi-valued attribute with
same primary key and
• other table contains multi-valued attribute and place a primary key in it.
• insert the primary key of first table in the second table as a foreign key.
1NF (First Normal Form) [Multivalued attribute]
Student
RollNo Name FailedinSubjects
101 Raj DS
101 Raj DBMS
102 Meet DBMS
102 Meet DS
103 Jeet DS
103 Jeet DBMS
103 Jeet DE
104 Harsh DBMS
104 Harsh DE
104 Harsh DS
105 Nayan DE
105 Nayan DBMS
105 Nayan DS
1NF (First Normal Form)
Problems:
But now we have introduced redundancy into table.
This can be eliminated using Second Normal
Form(2NF).
2NF (Second
Normal Form)
2NF (Second Normal Form)
This normal form makes use of function dependency and tries
to remove problem of redundant data that was introduces by
1NF.
Therefore before applying 2NF to a relation, it needs to satisfy
1NF condition.
There should be no Partial Dependency.
This normal form is given by E.F.Codd(1971).
2NF (Second Normal Form)
Conditions for 2NF
It is in 1NF and each table should contain a single primary key.
Note:
In most cases. 3rd normal form is the sufficient level of
decomposition . But some case requires the design to be further
formalized up to level of 4th as well as 5th . These are based on the
concept of multi valued dependency.
BCNF
(Boyce-Codd
Normal Form)
BCNF (Boyce-Codd Normal Form)
This normal form is govern by Raymond F. Boyce and
E. F. Codd (1974).
BCNF more rigorous form of 3NF.
The intention of BCNF is that 3NF does not
satisfactory handle the case of a relation processing
two or more composite or overlapping candidate keys.
Candidate Key is a column in a table which has the
ability to become a primary key.
A determinant is any attribute (simple or composite)
on which some other attribute is fully functionally
dependent.
BCNF (Boyce-Codd Normal Form)
Conditions for BCNF
Primary Key
Determinant Dependent
X Y
Decompose
Decompose
B → C, D → A
Candidate Key is BD
C → D, C → A, B → C
Candidate Key is B
A → B, BC → D, A → C
Candidate Key is A
ABC → D, D → A
UNF
Employee Employee Date of Department Department Project Project Project
Number Name Birth Code Name Code Description Supervisor
1 Raj 1-1-85 1 CE 1 IOT Patel
2 Meet 4-4-86 2 EC 2 PHP Shah
3 Suresh 2-2-85 1 CE 3 IOT Patel
1 Raj 1-1-85 1 CE 2 PHP Shah
How to normalize database? [1NF]
UNF
Employee Employee Date of Department Department Project Project Project
Number Name Birth Code Name Code Description Supervisor
1 Raj 1-1-85 1 CE 1 IOT Patel
2 Meet 4-4-86 2 EC 2 PHP Shah
3 Suresh 2-2-85 1 CE 1 IOT Patel
1 Raj 1-1-85 1 CE 2 PHP Shah
1NF
Employee Project
Number Code
1 1
2 2
3 1
1 2
How to normalize database? [1NF]
3NF
Employee Project
Number Code
Department Department
Code Name 1 1
1 CE 2 2
2 EC 3 1
1 2