Func Depend Normalization
Func Depend Normalization
DBMS
1
Functional Dependency
If there is a dependency from X to Y i.e. XY
2
If there is a dependency from A to B i.e. AB
A B A B A B A B
a 5 a 5 a 5 a 5
b 8 b 8 b 7 b 5
a 7 a 5 c 5 a 5
c 9 c 9 d 4 c 5
b 3 b 8 e 6 b 5
1. Invalid 2. Valid 3. Valid 4. Valid
3
Types of Functional Dependency
Full Functional Dependency
• If all non-prime/non-key attributes are entirely dependent on the prime/key
attribute/candidate key, is called full functional dependency.
Partial Dependency
• If some non-prime / non-key attributes are entirely dependent on the prime / key
attribute/candidate key & Some non-prime / non-key attributes are partially
dependent on the part of prime/key attribute/candidate key, is called partial
dependency.
Transitive Dependency
• If any non-prime/non-key attribute is dependent on other non-prime/non-key
attribute, is called transitive dependency.
4
Functional Dependencies
Example: To check dependency for the following A B C D
dependencies with data given in the table
i) ABC a1 5 4 3
ii) CDAB
b1 a 4 5
iii) BCD
a1 5 4 2
In i) a1 searching two values 5,4 in Ist & IIIrd row, here we
get same value of BC for the same value of A, b1 finding a,4 c1 b 4 6
and c1 finding b,4
this means i) dependency is valid
In ii) the values of CD(4,3 & 4,5 & 4,2 & 4,6) are unique
this means ii) dependency is valid
In iii) on the same value of B (value-5), we are getting
different values of CD (i.e 4,3 & 4,2)
this means iii) dependency is invalid
5
Functional Dependencies
Example: To check dependency is valid or invalid for the A B C
following dependencies with data given in the table
i) AB && BCA 2 3 6
ii) BC && ABC 4 6 6
iii) AC && BCA
4 8 4
In i) AB is invalid
this means i) dependency is invalid 2 5 4
In ii) BC is valid, because all values of B are unique
ABC is valid, because all values of AB are unique
this means ii) dependency is valid
In iii) AC is invalid
this means iii) dependency is invalid
6
Closure Set of Attributes
R1(A,B.C,D,E) R2(A,B.C,D,E,F) R3(A,B,C,D,E,F)
ABC ABC CDE
BD BCAD DAF
DA DE ECF
EF
B+ (closure set of B)-? (AB) + (closure set of AB)-? (DE) + (closure set of DE)-?
B=B AB=AB DE=DE
B=BD AB=ABC DE=ADEF
B=ABD AB=ABCD DE=ACDEF (Final)
B=ABCD(final) AB=ABCDE (BC)=BCDEAF=ABCDEF
AB=ABCDEF (final)
7
Finding Candidate Key (CK)
R1(A,B,C,D) R2(A,B,C,D) R3(A,B.C,D,E)
AB ABCD CD
BD DA DAB
DA EC
Here C is not dependent on Here B is not dependent on any Here E is not dependent on any
any other key other key other key
(AC) + =ABC (AB) + =ABCD (E) + =CE
=ABCD (BC) + =BC - No =CDE
(BC) + =BDC (BD) + =BDA =ABCDE
=ABDC =ABCD (E) is a CK.
=ABCD (AB) ,(BD) are CK.
(CD) + =CDA=ABCD
(AC) ,(BC) & (CD) are CK.
8
Finding Candidate Key (CK)
R4(A,B.C,D,E) R5(A,B.C,D,E,F) R6(A,B.C,D,E,F)
ABC ABC CDE
BD BCAD DAF
DA DE ECF
EF
Here E is not dependent on Here B is not dependent on any Here B is not dependent on any
any other key other key other key
(AE) + =ABCE (AB) +=ABC=ABCD (AB) +=AB -No
=ABCDE =ABCDE=ABCDEF (BC) +=BCDE=BCDEF
(BE) + =BDE (BC) +=ABCD=ABCDE =ABCDEF
=ABDE=ABCDE =ABCDEF (BD) +=BDAF -No
(CE) + =CE -No (BD) +=BDE=BDEF -No (BE) +=BECF = BCDEF
+
(DE) =ADE (BE) +=BEF -No =ABCDEF
=ABCDE (BF) +=BF -No (BF) +=BF -No
(AE) ,(BE) , (DE) are CK. (AB) ,(BC) are CK. (BC) ,(BE) are CK.
9
Normalization
What is Normalization?
Normalization is a database design technique that reduces data redundancy and
eliminates undesirable characteristics like Insertion, Update and Deletion Anomalies.
Normalization rules divides larger tables into smaller tables and links them using
relationships. The purpose of Normalization in SQL is to eliminate redundant
(repetitive) data and ensure data is stored logically.
10
First Normal Form (1NF)
Any relation (table) will be in 1NF if it has no repeating groups of data. Each cell in a
relation contain only one value, value should be atomic. That could not be decomposed
further into smaller parts.
Roll No. Name Subject Course Roll No. Name Subject Course
1011 Vikas DBMS MCA 1011 Vikas DBMS MCA
WT MCA 1011 Vikas WT MCA
TOC MCA
1011 Vikas TOC MCA
1012 Hemant DBMS MCA
WT MCA 1012 Hemant DBMS MCA
TOC MCA 1012 Hemant WT MCA
This is not allowed, this is not in 1NF 1012 Hemant TOC MCA
This is in 1NF
11
Second Normal Form (2NF)
Any relation (table) will be in 2NF if every non-prime attribute depends on the entire /
candidate key, not just part of it.
No non-prime attributes is partially dependent on a part of candidate key or entire key.
R(A,B,C,D) R:
ABD R1(A,B,D)
BC R2(B,C)
Relation R is converted in two relations R1 &
R2.This is now in 2NF.
(AB) +=ABCD Here
(B)=C In R1 D is fully dependent on AB (entire key)
Here, AB is a candidate key In R2 C is fully dependent on B (entire key)
A,B – Prime attribute
C,D – Non-prime attribute
D is entirely dependent on AB but C is
partially dependent on B, B is the part of
key. This relation is not in 2NF.
12
Third Normal Form (3NF)
Any relation (table) will be in 3NF if it is in 2NF and no non-prime attribute is
functionally dependent on other non-prime attribute.
No transitive dependency should be there.
R(B.C,D) R:
BC R1(B,C)
CD R2(C,D)
Relation R is converted in two relations R1 &
R2.This is now in 3NF.
Here, Here
B, C, D – Non-prime attributes In R1 C is fully dependent on B.
D is dependent on C and C is dependent on B, In R2 D is fully dependent on C.
This is the case of transitive dependency. This
relation is not in 3NF.
13