Lecture Slides available: PDF PowerPoint Normalisation - BCNFContents
Overview
Boyce-Codd Normal Form (BCNF)
Consider the following relation and determinants. R(a,b,c,d) Here, the first determinant suggests that the primary key of R could be changed from a,b to a,c. If this change was done all of the non-key attributes present in R could still be determined, and therefore this change is legal. However, the second determinant indicates that a,d determines b, but a,d could not be the key of R as a,d does not determine all of the non key attributes of R (it does not determine c). We would say that the first determinate is a candidate key, but the second determinant is not a candidate key, and thus this relation is not in BCNF (but is in 3rd normal form). Normalisation to BCNF - Example 1
Lets consider the database extract shown above. This depicts a special dieting clinic where the each patient has 4 appointments. On the first they are weighed, the second they are exercised, the third their fat is removed by surgery, and on the fourth their mouth is stitched closed… Not all patients need all four appointments! If the Patient Name begins with a letter before “P” they get a morning appointment, otherwise they get an afternoon appointment. Appointment 1 is either 09:00 or 13:00, appointment 2 10:00 or 14:00, and so on. From this (hopefully) make-believe scenario we can extract the following determinants: DB(Patno,PatName,appNo,time,doctor) Patno -> PatName Now we have to decide what the primary key of DB is going to be. From the information we have, we could chose: Example 1a - DB(Patno,PatName,appNo,time,doctor)
None:DB(Patno,PatName,appNo,time,doctor)
DB(Patno,appNo,time,doctor) R1(Patno,PatName)
None: so just as 2NF
time is enough to work out the appointment number of a patient. Now BCNF is satisfied, and the final relations shown are in BCNF. Example 1b - DB(Patno,PatName,appNo,time,doctor)
None:DB(Patno,PatName,appNo,time,doctor)
DB(Patno,time,doctor) R1(Patno,PatName) R2(time,appNo)
None: so just as 2NF
Summary - Example 1This example has demonstrated three things:
Example 2Grade_report(StudNo,StudName,(Major,Adviser, (CourseNo,Ctitle,InstrucName,InstructLocn,Grade)))
StudNo -> StudName CourseNo -> Ctitle,InstrucName InstrucName -> InstrucLocn StudNo,CourseNo,Major -> Grade StudNo,Major -> Advisor Advisor -> Major
Grade_report(StudNo,StudName,(Major,Advisor, (CourseNo,Ctitle,InstrucName,InstructLocn,Grade)))
Student(StudNo,StudName) StudMajor(StudNo,Major,Advisor) StudCourse(StudNo,Major,CourseNo, Ctitle,InstrucName,InstructLocn,Grade)
Student(StudNo,StudName) StudMajor(StudNo,Major,Advisor) StudCourse(StudNo,Major,CourseNo,Grade) Course(CourseNo,Ctitle,InstrucName,InstructLocn)
Student(StudNo,StudName) StudMajor(StudNo,Major,Advisor) StudCourse(StudNo,Major,CourseNo,Grade) Course(CourseNo,Ctitle,InstrucName) Instructor(InstructName,InstructLocn)
Only StudNo,Major is a candidate key.
Student(StudNo,StudName) StudCourse(StudNo,Major,CourseNo,Grade) Course(CourseNo,Ctitle,InstrucName) Instructor(InstructName,InstructLocn) StudMajor(StudNo,Advisor) Adviser(Adviser,Major) Problems BCNF overcomes
In BCNF we have two tables:
Returning to the ER Model
Normalisation ExampleLibraryConsider the case of a simple video library. Each video has a title, director, and serial number. Customers have a name, address, and membership number. Assume only one copy of each video exists in the library. We are given: video(title,director,serial) customer(name,addr,memberno) hire(memberno,serial,date) title->director,serial serial->title serial->director name,addr -> memberno memberno -> name,addr serial,date -> memberno What normal form is this?
Convert from 2NF to 3NF. Rewrite video(title,director,serial) To video(title,serial) serial(serial,director) Therefore the new relations become: video(title,serial) serial(serial,director) customer(name,addr,memberno) hire(memberno,serial,date) In BCNF? Check if every determinant is a candidate key. video(title,serial) Determinants are: title->director,serial Candidate key serial->title Candidate key video in BCNF serial(serial,director) Determinants are: serial->director Candidate key serial in BCNF customer(name,addr,memberno) Determinants are: name,addr -> memberno Candidate key memberno -> name,addr Candidate key customer in BCNF hire(memberno,serial,date) Determinants are: serial,date -> memberno Candidate key hire in BCNF Therefore the relations are also now in BCNF.
|
|