Upload
haneesha-muddasani
View
214
Download
0
Embed Size (px)
Citation preview
7/29/2019 lt16-NM
1/18
Database Systems and
ApplicationsLecture 16
Normalization
7/29/2019 lt16-NM
2/18
Types of Normal forms
First normal form Second normal form
Third normal form
Boyce-Codd normal form Fourth normal form
Fifth normal form
7/29/2019 lt16-NM
3/18
Steps in normalizationTable with multi-valued attributes
1st normal form
2nd normal form
3rd normal form
Boyce-Coddnormal form
4th normal form
5th normal form
Remove multi-valued attributes
Remove partialdependencies
Removeremaining anomalies
resulting from functionaldependencies
Remove transitive
dependencies
Remove multi-valued dependencies
Remove remaining
anomalies
7/29/2019 lt16-NM
4/18
Third Normal Form (3NF)
To fulfill 3NF a table should fulfill 2NFand in addition no non-key attributeshould be FFD of any other non-keyattribute.
That means ..
A relation is in 3NF if it is in 2NF andno transitive dependencies exist.
A transitive dependency in a relationis a functional dependency betweentwo or more non key attributes.
7/29/2019 lt16-NM
5/18
3NF (cont.)
Due to the transitivedependency, there will beupdate anomalies, like
Insertion anomaly:
Deletion anomaly:Modification anomaly:
7/29/2019 lt16-NM
6/18
Consider the following relation:(st_id, st_name, course_no,
course_name, sec_no,classroom,inst_id, inst_name,no_of_sections)
with the functional dependencies st_id st_name course_no course_name
,no_of_sections st_id , course_no, sec_no course_no, sec_no classroom, inst_id inst_id inst_name
7/29/2019 lt16-NM
7/18
R1( st_id ,st_name)
R2(course_no,course_name,no_of_sections,)
R3(st_id,course_no,sec_no,classroom,inst_id ,inst_name)
Now it is in 2 NF
7/29/2019 lt16-NM
8/18
st_id , course_no, course_no ,sec_no
course_no, sec_no classroom,inst_id
Therefore
st_id , course_no, classroom,inst_id
In the same way
course_no, sec_no classroom,inst_id
inst_id inst_name
Therefore
course no sec no inst name
7/29/2019 lt16-NM
9/18
(st_id , course_no, sec_no)
(course_no, sec_no ,classroom,
inst_id )
(inst_id ,inst_name )
7/29/2019 lt16-NM
10/18
cno cname , cno ins_ic
ins_ic chamber no
Decompose into
(cno,cname,ins_ic) (ins_ic,chamber no)
Example II for convertinginto 3NF
cno cname
ins_ic chamber
7/29/2019 lt16-NM
11/18
Boyce-Codd Normal Form(BCNF)
Boyce-Codd normal form (BCNF)
A relation is in BCNF, if and only if, every determinant is a
candidate key.
The difference between 3NF and BCNF is that for a functionaldependency A B, 3NF allows this dependency in a relationif B is a primary-key attribute and A is not a candidate key,
whereas BCNF insists that for this dependency to remain in arelation, A must be a candidate key.
7/29/2019 lt16-NM
12/18
FD1 clientNo, interviewDate interviewTime, staffNo, roomNo(Primary Key)
FD2 staffNo, interviewDate, interviewTime clientNo , roomNo(Candidate key)
FD3 roomNo, interviewDate, interviewTime clientNo, staffNo(Candidate key)
FD4 staffNo, interviewDate roomNo (not a candidate key)
As a consequece the ClientInterview relation may suffer from updateanmalies.
For example, two tuples have to be updated if the roomNo need be changedfor staffNo SG5 on the 13-May-02.
ClientInterview
ClientNo interviewDate interviewTime staffNo roomNo
CR76 13-May-02 10.30 SG5 G101
CR75 13-May-02 12.00 SG5 G101
CR74 13-May-02 12.00 SG37 G102
CR56 1-Jul-02 10.30 SG5 G102
CR55 13-May-02 10:30 SG6 G103
7/29/2019 lt16-NM
13/18
Example of BCNFTo transform the ClientInterview relation to BCNF, we must remove
the violating functional dependency by creating two new relations
called Interview and StaffRoom as shown below,
Interview (clientNo, interviewDate, interviewTime, staffNo)
StaffRoom(staffNo, interviewDate, roomNo)
ClientNoClientNo interviewDateinterviewDate interviewTimeinterviewTime staffNostaffNoCR76CR76 13-May-0213-May-02 10.3010.30 SG5SG5
CR75CR75 13-May-0213-May-02 12.0012.00 SG5SG5
CR74CR74 13-May-0213-May-02 12.0012.00 SG37SG37
CR56CR56 1-Jul-021-Jul-02 10.3010.30 SG5SG5
CR55 13-May-02 10:30 SG6
staffNostaffNo interviewDateinterviewDate roomNoroomNoSG5SG5 13-May-0213-May-02 G101G101
SG37SG37 13-May-0213-May-02 G102G102
SG5SG5 1-Jul-021-Jul-02 G102G102SG6 13-May-02 G103
Interview
StaffRoom
BCNF Interview and StaffRoom relations
7/29/2019 lt16-NM
14/18
Another BCNF Example
7/29/2019 lt16-NM
15/18
Fourth Normal Form
Multivalued Dependency is a rule that twoattributes or set of attributes areindependent of one another. i.e., when
there are atleast three attributes(e.g., A,B, C) in a relation, with well defined set ofB and C values for each A value, but thoseB and C values are independent of each
other. A relation is in 4NF if it is in BCNF and
contains no multivalued dependencies.
7/29/2019 lt16-NM
16/18
Multi ValuedDependency
Let R be a relation and A and Barbitrary sets of attributes of R.
There is a multi-valued dependency
from A to BA Bif and only each A value exactly
determines a set of B values,independently of the other attributes
7/29/2019 lt16-NM
17/18
4NF (cont.)COURSE_OFFERING
c_no teacher_id textbook_code
CSC352 245 T-1
CSC352 245 T-2
ISC332 300 T-1
ISC332 300 T-2CSC374 250 T-4
CSC374 250 T-5
7/29/2019 lt16-NM
18/18
4NF (cont.) Ex: (c_no, teacher_id, textbook_code)
COURSE_OFFERING
In this example all the 3 attributes are candidate key,but teacher_id and textbook_code dont have anyrelationship. To remove the multivalued dependency,decompose the relation in two new relations.
course_no techer_id textbook_code
course_no techer_id course_no textbook_code