0% found this document useful (0 votes)
32 views

Normalization

Uploaded by

shrey patel
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Normalization

Uploaded by

shrey patel
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

First normal form

Rule :
According to the ef code the table should not contain multivalued attribute
For example there is a student table where there are three columns i.e
Roll no Name Course
1 sai c/c++
2 Harch java
3 omkar c/Dbms
Here we can see the course column contains more than one values so it is not in first normal form.
Conver the table then in 1NF
Rollno name course
1 sai c
1 sai c++
2 harsh java
3 omkar c
3 omkar dbms
So now the table is In first normal form
So the primary key of new table is Roll no and course column
In the same way we can represent the same like this
Rollno name course1 course2
1 sai c c++
2 harsh java NULL
3 omkar c DBMS
Now what can be the primary key of this table
So Roll no is the primary key.
But there is one problem that one student is enrolled in n number of courses and other student are
registered in the minimal number of courses either 1 or 0 so there will be so many times null repeated
in all the rows. To solve this problem we will divide the table in to two tables

Table 1
Rollno Name
1 Sai
2 Harsh
3 Omkar
Table 2
Rollno Course
1 c
2 c++
3 java
4 c
5 dbms
Primary key of base table1 is rollno and table 2 has foreign key as rollno and primary key as
rollno and course.

Clousure method
It help to find all the candidate keys in the table.

Example 1
R(ABCD)
FD {A->B , B->C , C->D}
A+ = BCDA
B+ = BCD (Not a candidate key)
C+ = CD (Not a candidate key)
D+ = D (Not a candidate key)
(AB)+ = ABCD (Not a candidate key bcz candidate key should be minimal so it is a super
key.
CK={A}
PA={A}
Non prime attribute={B,C,D}

EXAMPLE 2
FD={A->B, B->C, C->D, D->A}
A+ = ABCD
B+ = BCDA
C+ = CDAB
D+ =DABC
CK = {A,B,C,D}
Now in exam they can also ask what is prime attribute
So prime attributes are the attribute which is used to make the candidate key
PA={A,B,C,D}
Non prime attributes={}

Functional Dependincy
86413
Functional dependency is a method which describes the relationship within the attributes
For example
X->Y means X determines Y
Or Y is determined by X
Here X is Determinant and Y is dependent.
Like sid-> sname
sname
Ranjit
Ranjit
Now there is confusion that both Ranjit are same or different so now we will look at the sid to
determine both of them
So if both the sid is different then both are different otherwise same.
Functional dependency is of two types
1. Trivial
2. Non Trivial

Trivial FD
Suppose if X->Y then Y is subset of x
Trivial FD Are always true;
In trivial FD if we take l.h.s intersection r.h.s then It will not give null. For example
Sid,sname -> sid
So intersection of both side is SID

Non trivial FD
X->Y
In this FD L.H.S intersection R.H.S is always null
For example
Sid->sname
Sid->semester
In this we need to check the cases that is the FD is valid or not valid.

Properties ofFD
Reflexivity if y is subset of x then X->Y
Augmentation : if X->Y then XZ->YZ i.e sid->sname is true then sid,phn->sname,phn is also
true.
Transitive : if X->Y and Y->Z then X->Z
Union : if X->Y and X->Z then x->YZ
Decomposition : if X->YZ then X->Y and X->Z
XY->Z then it is false that X->Z , Y->Z
Pseudo transitive : if X->Y and WY->Z then WX->Z
Composition : if X->Y and Z->W then XZ ->YW

2NF
Rules of 2NF is that
1. The table should be in 1NF
2. The table should not contain any partial dependency..ie all the non prime
attributes should be fully functional dependent on candidate key
For example
Customer table
Customer_id store_idlocation
1 1 Delhi
1 3 Mumbai
2 1 Delhi
3 2 Banglore
4 3 Mumbai
But here the location is determined by the store id itself not by both d=store id and the
cust-id so we can make it in 2NF by dividing it
Table 1
Customer_id Store_id
1 1
1 3
2 1
3 2
4 3

Table 2
Store_id Location
1 Delhi
2 Banglore
3 Mumbai
Now we can say that in table 1 both the col are the candidate key so it is in 2nf and in table 2
the store_id is candidate key and location column is dependent on the store_id so this is also in the
2NF.
Gate question
A relation is R(ABCDEF)
FD{ C->F , F->A, EC->D , A->B}
Solution
Now the candidate keys are
(EC)+ = ECDABF
CK = { EC}
There is no candidate key other than EC all are the super keys.
2nd step is to find all the prime attribute i.e {E,C}
All the non prime attributes are { A, B, D, F}
Now as we know that a part of the candidate key should not define a attribute. So lets check one by
one with all the available relations.
As we can see the first relation C->F is a part of EC candidate key so this is a partial dependency.
Which is not allowed in the 2NF.

3NF
Rules of third normal form
1. The table must be in the 2nF
2. There should be no transitive dependency in the table
What is transitive dependency?
Any non prime attribute cannot define any other non prime attribute.
For example,
There is a state table
Rollno State City
1 punjab Mohali
2 haryana Amtala
3 Punjab Mohali
4 Haryaha Ambala
5 Bihar Patna
Here FD is Rollno -> state
State-> city
Here Rollno is CK and it is defining state which is correct but the state which is a non prime
attribute and it is defining city which Is also a non prime attribute. Which is a transitive
dependency.
To solve this problem and make this table in 3rd normal form we will divide the table into separate
representations.
Table 1
Rollno state
1 punjab
2 haryana
3 punjab
4 haryana
5 bihar

Table 2
State City
Punjab Mohali
Haryana Amtala
Punjab Mohali
Haryana Ambala
Bihar Patna

Table 3
Roll no City
1 Mohali
2 Amtala
3 Mohali
4 Ambala
5 Patna
Example 2
R(ABCD)
FD {AB->CD , D->A}
(AB)+ = ABCD
(DB)+ DBACD
CK={AB,DB}
Prime attributes ={A,B,D}
Non-Prime attribute = {C}
Check for transitive dependency. To do so for each FD check L.H.S must be a candidate key or
super key or R.H.S is a prime attribute.
Check AB->CD
LHS is a CK true
RHS is a prime attribute TRUE
Check D->A
LHS is a candidate key false
RHS is a prime attribute true
So false or true = true
Hence the table Is already in a 3NF.

BCNF
Boyce code normal form
BCNF Is also known as special case of 3rd normal form.
Rules
1. Table should be in 3NF
2. LHS of every FD should be a candidate key.
For example
Student table
Rollno name voterid Age
1 ravi ko123 20
2 varun Mo23 21
3 ravi k786 23
4 Rahul D286 21
CK = {Rollno,Voterid}
FD { Rollno->name, Rollno-> Voterid, voterid->age, Voterid -> Rollno}

You might also like