Relational Database Design
Relational Database Design
(DBMS)
GTU # 3130703
Unit-4
Relational
Database
Design
Prof. Firoz A Sherasiya
Computer Engineering
Department
Darshan Institute of Engineering & Technology, Rajkot
[email protected]
9879879861
Looping
Outline
• Functional Dependency
• Definition and types of FD
• Armstrong's axioms (inference rules)
• Closure of FD set
• Closure of attribute set
• Canonical cover
• Decomposition and its types
• Anomaly in database design and its
types
• Normalization and normal forms
• 1NF
• 2NF
• 3NF
• BCNF
• 4NF
• 5NF
Functional Dependency
(FD) and
its types
Section – 1.1
What is Functional Dependency (FD)?
Let R be a relation schema having n attributes A1, A2, A3,…, An.
Stud
ent
Roll Nam SP B
No e I L
101 Raju 8 0
102 Mites 7 1
h
103 Jay 7 0
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.
#3130703 (DBMS) Unit 4 – Relational
Prof. Firoz A Sherasiya 4
Diagrammatic representation of Functional
Dependency (FD)
X→ {X1, X2} X → {Y1,
Y →Y 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}.
account_no balan branch
ce
#3130703 (DBMS) Unit 4 – Relational
Prof. Firoz A Sherasiya 5
Types of Functional Dependency (FD)
Full Functional Dependency
In a relation, the attribute B is fully functional dependent on A if B is functionally
dependent on A, but not on any proper subset of A.
Eg. {Roll_No, Semester, Department_Name} → SPI
We need all three {Roll_No, Semester, Department_Name} to find SPI.
Partial Functional Dependency
In a relation, the attribute B is partial functional dependent on A if B is functionally
dependent on A as well as on any proper subset of A.
If there is some attribute that can be removed from A and the still dependency holds
then it is partial functional dependancy.
Eg. {Enrollment_No, Department_Name} → SPI
Enrollment_No is sufficient to find SPI, Department_Name is not required to find
SPI.
Unio Compositi
n on
If A → B and A → C If A → B and C → D
then A → BC then AC → BD
We
have
A→B Transitivity
A→H
B→H rule
We
have
CG → H
Union rule CG → HI
CG → I
We
have
A→C Pseudo-
transitivity AG → I
CG → I rule
We
have Augmentation
A→C AG → CG
rule
AG → CG Transitivity
AG → I
CG → I rule
Several members of
F+ CG
F+ = (A → H, are→ HI, AG →
I)
F+ = (A → BC, CD → EF, A → E, AD → E, AD
→ F)
D → AC Decomposition D→A&D
D → AC & D → Rule
Union Rule →
DC→ ACE
E
F+ = (D → A, D → C, D → ACE)
A+ = ABCDE
CD+ = ABCDE
B+ = BD
BC+ = ABCDE
E+ = ABCDE
#3130703 (DBMS) Unit 4 – Relational
Prof. Firoz A Sherasiya 24
Canonical cover
Section – 4
What is extraneous attributes?
Let us consider a relation R with schema R = (A, B, C) and set of functional
dependencies FDs F = { AB → C, A → C }.
In AB → C, B is extraneous attribute. The reason is, there is another FD
A → C, which means when A alone can determine C, the use of B is
unnecessary (extra).
An attribute of a functional dependency is said to be extraneous if we can
remove it without changing the closure of the set of functional
dependencies.
F = {A → B, A →
Decomposition C} Union Rule
Rule
Fc = {A → BC}
What we do in normalization?
Normalization generally involves splitting an existing table into multiple (more
than one) tables, which can be re-joined or linked each time a query is issued
(executed).
A relation R is in first normal form (1NF) if and only if it does not contain
any composite attribute or multi-valued attributes or their
combinations.
OR
A relation R is in first normal form (1NF) if and only if all underlying
domains contain atomic values only.
Let a relation R with attributes ABCD with FDs B → C, D → A. Find keys for
relation R.
The core is BD. B determines C and D determines A, so BD is a key. Therefore BD is
the key.
Identify the best normal form that R satisfies (1NF, 2NF, 3NF or BCNF).
Candidate Key is BD
Relation R is in 1NF but not 2NF. In above FDs, there is a partial dependency
(As per FD B → C, C depends only on B but Key is BD so C is partial depends on key
(BD))
(As per FD D → A, A depends only on D but Key is BD so A is partial depends on key
(BD))
Identify the best normal form that R satisfies (1NF, 2NF, 3NF or BCNF).
Candidate Key is B
Relation R is in 2NF but not 3NF. In above FDs, there is a transitive dependency
(As per FDs B → C & C → D then B → D so D is transitive depends on key (B))
(As per FDs B → C & C → A then B → A so A is transitive depends on key (B))
Identify the best normal form that R satisfies (1NF, 2NF, 3NF or BCNF).
Candidate Key is A
Relation R is in 2NF but not 3NF. In above FDs, there is a transitive dependency
(As per FDs A → B & A → C then A → BC using union rule) and
(As per FDs A → BC & BC → D then A → D so D is transitive depends on key (A))
Identify the best normal form that R satisfies (1NF, 2NF, 3NF or BCNF).
Employ Employ
Employ Date Departm Departm Proje Project Project
ee ee
ee of ent ent ct Descript Supervi
Numbe Numbe
Name Birth Code Name Code ion sor
r r
1 Raj 1-1-85 1 CE 1 1 IOT Patel
2 Meet 4-4-86 2 EC 2 2 PHP Shah
3 Suresh 2-2-85 1 CE 3 1 IOT Patel
#3130703 (DBMS) Unit 4 – Relational
Prof. Firoz A Sherasiya 1 2 PHP Shah 80
How to normalize database?
1NF
Employ Employ
Employ Date Departm Departm Proje Project Project
ee ee
ee of ent ent ct Descript Supervi
Numbe Numbe
Name Birth Code Name Code ion sor
r r
1 Raj 1-1-85 1 CE 1 1 IOT Patel
2 Meet 4-4-86 2 EC 2 2 PHP Shah
3 Suresh 2-2-85 1 CE 3 1 IOT Patel
2NF
1 2 PHP Shah
Employ Proje Project Project Employ
Employ Date Departm Departm Proje
ee ct Descript Supervi ee
ee of ent ent ct
Numbe Code ion sor Numbe
Name Birth Code Name Code
r 1 IOT Patel r
1 Raj 1-1-85 1 CE 1 1
2 PHP Shah
2 Meet 4-4-86 2 EC 2 2
3 Suresh 2-2-85 1 CE 3 1
#3130703 (DBMS) Unit 4 – Relational
Prof. Firoz A Sherasiya 1 812
How to normalize database?
3NF
Thank
You