Sei sulla pagina 1di 18

Database Systems and Applications

Lecture 16 Normalization

Types of Normal forms


First normal form Second normal form Third normal form Boyce-Codd normal form Fourth normal form Fifth normal form

Steps in normalization
Table with multivalued attributes 1st normal form
Remove partial dependencies Remove multivalued attributes

2nd normal form

Remove transitive dependencies Remove remaining anomalies resulting from functional dependencies Remove multivalued dependencies Remove remaining anomalies

3rd normal form

Boyce-Codd normal form

4th normal form

5th normal form

Third Normal Form (3NF)


To fulfill 3NF a table should fulfill 2NF and in addition no non-key attribute should be FFD of any other non-key attribute. That means .. A relation is in 3NF if it is in 2NF and no transitive dependencies exist. A transitive dependency in a relation is a functional dependency between two or more non key attributes.

3NF (cont.)
Due to the transitive dependency, there will be update anomalies, like

Insertion anomaly: Deletion anomaly: Modification anomaly:

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

R1( st_id ,st_name) R2(course_no,course_name ,no_of_sections,) R3(st_id,course_no,sec_no,classroom,inst_i d ,inst_name) Now it is in 2 NF

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

(st_id , course_no, sec_no) (course_no, sec_no ,classroom, inst_id ) (inst_id ,inst_name )

cno

Example II for converting into 3NF


cnam ins_ic chambe e r

cno cname , cno ins_ic ins_ic chamber no Decompose into (cno,cname,ins_ic) (ins_ic,chamber no)

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 functional dependency A B, 3NF allows this dependency in a relation if B is a primary-key attribute and A is not a candidate key, whereas BCNF insists that for this dependency to remain in a relation, A must be a candidate key.

ClientInterview
ClientNo
CR76 CR75 CR74 CR56 CR55

interviewDate
13-May-02 13-May-02 13-May-02 1-Jul-02 13-May-02

interviewTime
10.30 12.00 12.00 10.30 10:30

staffNo
SG5 SG5 SG37 SG5 SG6

roomNo
G101 G101 G102 G102 G103

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 update anmalies. For example, two tuples have to be updated if the roomNo need be changed for staffNo SG5 on the 13-May-02.

Example of BCNF
To 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)
Interview
ClientNo
CR76 CR75 CR74 CR56 CR55

interviewDate
13-May-02 13-May-02 13-May-02 1-Jul-02 13-May-02

interviewTime
10.30 12.00 12.00 10.30 10:30

staffNo
SG5 SG5 SG37 SG5 SG6

StaffRoom
staffNo
SG5 SG37 SG5 SG6

interviewDate
13-May-02 13-May-02 1-Jul-02 13-May-02

roomNo
G101 G102 G102 G103

BCNF Interview and StaffRoom relations

Another BCNF Example

Fourth Normal Form


Multivalued Dependency is a rule that two attributes or set of attributes are independent of one another. i.e., when there are atleast three attributes(e.g., A, B, C) in a relation, with well defined set of B and C values for each A value, but those B and C values are independent of each other. A relation is in 4NF if it is in BCNF and contains no multivalued dependencies.

Multi Valued Dependency


Let R be a relation and A and B arbitrary sets of attributes of R. There is a multi-valued dependency from A to B A B if and only each A value exactly determines a set of B values, independently of the other attributes

4NF (cont.)
COURSE_OFFERING

c_no CSC352 CSC352 ISC332 ISC332 CSC374 CSC374

teacher_id 245 245 300 300 250 250

textbook_code T-1 T-2 T-1 T-2 T-4 T-5

4NF (cont.)
Ex: (c_no, teacher_id, textbook_code) COURSE_OFFERING

course_no

techer_id

textbook_code

In this example all the 3 attributes are candidate key, but teacher_id and textbook_code dont have any relationship. To remove the multivalued dependency, decompose the relation in two new relations.

course_no techer_id

course_no textbook_code

Potrebbero piacerti anche