DBMS Unit-5
DBMS Unit-5
Nilesh Khodifad
Outline
• Functional Dependency (FD) and its Types
• Armstrong's axioms OR Inference rules
• Closure of a set of FDs
• Closure of attribute sets
• Decomposition
• Anomaly and its types
• Normalization and normal forms
What is Functional Dependency(FD)
Let R be a relation schema having n attributes A1, A2, A3,…, An.
Student
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}.
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.
Types of Functional Dependency (FD)
Transitive Functional Dependency
In a relation, if attribute(s) A → B and B → C, then A → C (means C is transitively
depends on A via B).
We have
A→B Transitivity
rule A→H
B→H
Closure of a set of FDs [Example]
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
Closure of a set of FDs [Example]
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-
AG → I
CG → I transitivity rule
Closure of a set of FDs [Example]
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 AG → I
Transitivity rule
CG → I
Closure of a set of FDs [Example]
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)
Find out the closure of F.
F+ = (A → H, CG → HI, AG → I)
Closure of a set of FDs [Example]
Compute the closure of the following set F of functional dependencies
FDs for relational schema R = (A,B,C,D,E,F):
F = (A → B, A → C, CD → E, CD → F, B → E)
Find out the closure of F.
Closure of a set of FDs [Example]
Compute the closure of the following set F of functional
dependencies FDs for relational schema R = (A,B,C,D,E):
F = (AB → C, D → AC, D → E )
Find out the closure of F.
F+ = (D → A, D → C, D → ACE)
What is a closure of attribute sets?
Given a set of attributes α, the closure of α under F is the set of
attributes that are functionally determined by α under F.
It is denoted by α+. Algorithm
Suppose a new department (IT) has been started by the organization but initially there is no
employee appointed for that department.
We want to insert that department detail in Emp_Dept table.
But the tuple for this department cannot be inserted into this table as the EID will have
NULL value, which is not allowed because EID is primary key.
This kind of problem in the relation where some tuple cannot be inserted is known as insert
anomaly.
Delete anomaly
Consider a relation Emp_Dept(EID, Ename, City, DID, Dname, Manager) EID as a primary
key
Now consider there is only one employee in some department (IT) and that employee
leaves the organization.
So we need to delete tuple of that employee (Jay).
But in addition to that information about the department also deleted.
This kind of problem in the relation where deletion of some tuples can lead to loss of
some other data not intended to be removed is known as delete anomaly.
Update anomaly
Consider a relation Emp_Dept(EID, Ename, City, Dname, Manager) EID as a primary key
Suppose the manager of a (CE) department has changed, this requires that the Manager in
all the tuples corresponding to that department must be changed to reflect the new
status.
If we fail to update all the tuples of given department, then two different records of
employee working in the same department might show different Manager lead to
inconsistency in the database.
How to deal with insert, delete and update anomaly
What is normalization?
Normalization is the process of removing redundant data from
tables to improve data integrity, scalability and storage efficiency.
data integrity (completeness, accuracy and consistency of data)
scalability (ability of a system to continue to function well in a growing
amount of work)
storage efficiency (ability to store and manage data that consumes the least
amount of space)
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).
How many normal forms are there?
Normal forms:
1NF (First normal form)
2NF (Second normal form)
3NF (Third normal form)
BCNF (Boyce–Codd normal form)
4NF (Forth normal form)
5NF (Fifth normal form)
Problem: For example, in case of a joint account multiple (more than one) customers have
common (one) accounts.
If an account ’A01’ is operated jointly by two customers says ’C01’ and ’C02’ then data
values for attributes Balance and BranchName will be duplicated in two different tuples of
customers ’C01’ and ’C02’.
2NF (Second Normal Form) [Example]
Solution: Decompose relation in such a way that resultant relations do not have any
partial FD.
Remove partial dependent attributes from the relation that violets 2NF.
Place them in separate relation along with the prime attribute on which they are
fully dependent.
The primary key of new relation will be the attribute on which it is fully dependent.
Keep other attributes same as in that table with the same primary key.
3NF (Third Normal Form)
Conditions for 3NF
Solution: Decompose relation in such a way that resultant relations do not have any transitive FD.
Remove transitive dependent attributes from the relation that violets 3NF.
Place them in a new relation along with the non-prime attributes due to which transitive
dependency occurred.
The primary key of the new relation will be non-prime attributes due to which transitive
dependency occurred.
Keep other attributes same as in the table with same primary key and add prime attributes of
other relation into it as a foreign key.
BCNF (Boyce-Codd Normal Form)
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.
Let a relation R with attributes ABCD with FDs A → B, BC → D and A → C. Find keys for
relation R.
The core is A. A determines B and C which determine D, so A is a key. Therefore A is
the key.
Find (candidate) key & check for normal forms [Example]
Suppose you are given a relation R with four attributes ABCD. For each of the following
sets of FDs, do the following: F = (B → C, D → A)
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))
Find (candidate) key & check for normal forms [Example]
Suppose you are given a relation R with four attributes ABCD. For each of the following
sets of FDs, do the following: F = (C → D, C → A, B → C)
Identify the best normal form that R satisfies (1NF, 2NF, 3NF or BCNF).
Candidate Key is B
Identify the best normal form that R satisfies (1NF, 2NF, 3NF or BCNF).
1NF
How to normalize database?
1NF
2NF
How to normalize database?
3NF
Employee Employee Date of Department Department Department
Number Name Birth Code Code Name
1 Raj 1-1-85 1 1 CE
2 Meet 4-4-86 2 2 EC
3 Suresh 2-2-85 1
Employee Project
Number Code
Project Project Project
1 1
Code Description Supervisor
1 IOT Patel 2 2
2 PHP Shah 3 1
1 2
Thank You!!!
www.paruluniversi
ty.ac.in