Download presentation
Presentation is loading. Please wait.
Published byHarry Lindsey Modified over 9 years ago
2
B. Information Technology CMPB245: Database Design Normalization Pt. 2
3
2 Objectives Identify the Boyce-Codd Normal Form (BCNF) Normalize a given table from Unnor-malized Form (UNF) to Boyce-Codd Nor-mal Form (BCNF)
4
The Boyce-Codd Normal Form Objective 1
5
4 Boyce-Codd Normal Form (BCNF) A relation is in BCNF – If and only if every determinant is a candidate key Identify all the determinants Make sure they are candidate keys – If this is true, then the relation is in BCNF
6
5 Boyce-Codd Normal Form (BCNF) BCNF is violated when a relation – contains two or more composite candidate keys – that overlaps and share at least one common attribute
7
6 CLIENT_INTERVIEW Client_NoInterview_DateInterview_TimeStaff_NoRoom_No CR7613-May-9510.30SG5G101 CR5613-May-9512.00SG5G101 CR7413-May-9512.00SG37G102 CR561-Jul-9510.30SG5G102 Boyce-Codd Normal Form Example Consider the Client_Interview relation
8
7 Boyce-Codd Normal Form Example Identify all the candidate keys, i.e. which will produce unique rows CLIENT_INTERVIEW Client_NoInterview_DateInterview_TimeStaff_NoRoom_No CR7613-May-9510.30SG5G101 CR5613-May-9512.00SG5G101 CR7413-May-9512.00SG37G102 CR561-Jul-9510.30SG5G102
9
8 Boyce-Codd Normal Form Example By itself, all attributes cannot be a candidate key CLIENT_INTERVIEW Client_NoInterview_DateInterview_TimeStaff_NoRoom_No CR7613-May-9510.30SG5G101 CR5613-May-9512.00SG5G101 CR7413-May-9512.00SG37G102 CR561-Jul-9510.30SG5G102
10
9 Boyce-Codd Normal Form Example (Client_No, Interview_Date) both identifies a unique row and is a candidate key -- (Set 1) CLIENT_INTERVIEW Client_NoInterview_DateInterview_TimeStaff_NoRoom_No CR7613-May-9510.30SG5G101 CR5613-May-9512.00SG5G101 CR7413-May-9512.00SG37G102 CR561-Jul-9510.30SG5G102
11
10 Boyce-Codd Normal Form Example What about (Staff_No, Interview_Date) together? – No, because there are two rows CLIENT_INTERVIEW Client_NoInterview_DateInterview_TimeStaff_NoRoom_No CR7613-May-9510.30SG5G101 CR5613-May-9512.00SG5G101 CR7413-May-9512.00SG37G102 CR561-Jul-9510.30SG5G102
12
11 Boyce-Codd Normal Form Example What about (Staff_No, Interview_ Date, Interview_ Time) together? – Yes, they can be another candidate key - (Set 2) CLIENT_INTERVIEW Client_NoInterview_DateInterview_TimeStaff_NoRoom_No CR7613-May-9510.30SG5G101 CR5613-May-9512.00SG5G101 CR7413-May-9512.00SG37G102 CR561-Jul-9510.30SG5G102
13
12 Boyce-Codd Normal Form Example Since there are two sets of composite candidate key, then BCNF could be vio-lated 5555 CLIENT_INTERVIEW Client_NoInterview_DateInterview_TimeStaff_NoRoom_No CR7613-May-9510.30SG5G101 CR5613-May-9512.00SG5G101 CR7413-May-9512.00SG37G102 CR561-Jul-9510.30SG5G102
14
13 Boyce-Codd Normal Form Example Try use (Client_No, Interview_Date) as the primary key CLIENT_INTERVIEW Client_NoInterview_DateInterview_TimeStaff_NoRoom_No CR7613-May-9510.30SG5G101 CR5613-May-9512.00SG5G101 CR7413-May-9512.00SG37G102 CR561-Jul-9510.30SG5G102
15
14 Boyce-Codd Normal Form Example Then, identify all functional dependen-cies Identify all the determinants CLIENT_INTERVIEW Client_NoInterview_DateInterview_TimeStaff_NoRoom_No CR7613-May-9510.30SG5G101 CR5613-May-9512.00SG5G101 CR7413-May-9512.00SG37G102 CR561-Jul-9510.30SG5G102
16
15 Boyce-Codd Normal Form Example Client_No, Interview_Date Interview_TimeStaff_NoRoom_No Staff_No, Interview_Date Room_No Staff_No, Interview_Date, Interview_Time Client_No CLIENT_INTERVIEW Client_NoInterview_DateInterview_TimeStaff_NoRoom_No CR7613-May-9510.30SG5G101 CR5613-May-9512.00SG5G101 CR7413-May-9512.00SG37G102 CR561-Jul-9510.30SG5G102
17
16 Boyce-Codd Normal Form Example The candidate keys overlap and share a common attribute Interview_Date Hence, the BCNF is violated Client_No, Interview_Date Interview_TimeStaff_NoRoom_No Staff_No, Interview_Date Room_No Staff_No, Interview_Date, Interview_Time Client_No Client_No, Interview_Date Staff_No, Interview_Date, Interview_Time
18
17 Boyce-Codd Normal Form Example It is also not in BCNF – Due to the presence of the (Staff_No, Inter- view_Date) determinant – Which is not a candidate key 4444 Staff_No, Interview_Date Client_No, Interview_Date Interview_TimeStaff_NoRoom_No Room_No Staff_No, Interview_Date, Interview_Time Client_No Staff_No, Interview_Date
19
18 Boyce-Codd Normal Form Example Normalize Client_Interview relation to BCNF by – removing the violating functional dependency based on (Staff_No, Interview_Date) determinant Client_No, Interview_Date Interview_TimeStaff_NoRoom_No Staff_No, Interview_Date Room_No Staff_No, Interview_Date, Interview_Time Client_No
20
19 Boyce-Codd Normal Form Example CLIENT_INTERVIEW Client_NoInterview_DateInterview_TimeStaff_NoRoom_No CR7613-May-9510.30SG5G101 CR5613-May-9512.00SG5G101 CR7413-May-9512.00SG37G102 CR561-Jul-9510.30SG5G102
21
20 Boyce-Codd Normal Form Example Client_NoInterview_DateInterview_TimeStaff_No CR7613-May-9510.30SG5 CR5613-May-9512.00SG5 CR7413-May-199512.00SG37 CR561-Jul-9510.30SG5 Staff_NoInterview_DateRoom_No SG513-May-95G101 SG3713-May-1995G102 SG51-Jul-95G102 INTERVIEW STAFF_ROOM
22
Review of Normalization Process (UNF to BCNF) Objective 2
23
22 A DreamHome Scenario DreamHome Co. manages property on behalf of the owners The company’s staffs inspect properties A staff may inspect several properties at a given date A property is inspected once on that date A staff is allocated a car for the day
24
23 Property_NoPAddressIDateITimeCommentsStaff_NoSNameCar_Reg PG46 Lawrence Street,18-Oct-9410.00Need to replace crockerySG37Anne BeechM231 JGR Glasgow 22-Apr-9509.00In good orderSG14David FordM533 HDR 1-Oct-9512.00Damp rot in bathroomSG14David FordN721 HFR PG165 Novar Drive,22-Apr-9513.00Replace living roomSG14David FordM533 HDR Glasgowcarpet 24-Oct-9514.00Good conditionSG37Ann BeechN721 HFR PROPERTY_INSPECTION TABLE Unnormalized Form (UNF) Transfer some sample information from the report into a table – This table is the Unnormalized (UNF) table
25
24 Unnormalized Form (UNF) Identify the key attributes for table – The key attribute is Property_No Property_NoPAddressIDateITimeCommentsStaff_NoSNameCar_Reg PG46 Lawrence Street,18-Oct-9410.00Need to replace crockerySG37Anne BeechM231 JGR Glasgow 22-Apr-9509.00In good orderSG14David FordM533 HDR 1-Oct-9512.00Damp rot in bathroomSG14David FordN721 HFR PG165 Novar Drive,22-Apr-9513.00Replace living roomSG14David FordM533 HDR Glasgowcarpet 24-Oct-9514.00Good conditionSG37Ann BeechN721 HFR PROPERTY_INSPECTION TABLE
26
25 First Normal Form (1NF) First Approach Identify the repeating group in the unnormalized table Property_NoPAddressIDateITimeCommentsStaff_NoSNameCar_Reg PG46 Lawrence Street,18-Oct-9410.00Need to replace crockerySG37Anne BeechM231 JGR Glasgow 22-Apr-9509.00In good orderSG14David FordM533 HDR 1-Oct-9512.00Damp rot in bathroomSG14David FordN721 HFR PG165 Novar Drive,22-Apr-9513.00Replace living roomSG14David FordM533 HDR Glasgowcarpet 24-Oct-9514.00Good conditionSG37Ann BeechN721 HFR PROPERTY_INSPECTION TABLE
27
26 First Normal Form (1NF) First Approach The repeating attributes are – IDate, ITime, Comments, Staff_No, SName, Car_Reg Property_NoPAddressIDateITimeCommentsStaff_NoSNameCar_Reg PG46 Lawrence Street,18-Oct-9410.00Need to replace crockerySG37Anne BeechM231 JGR Glasgow 22-Apr-9509.00In good orderSG14David FordM533 HDR 1-Oct-9512.00Damp rot in bathroomSG14David FordN721 HFR PG165 Novar Drive,22-Apr-9513.00Replace living roomSG14David FordM533 HDR Glasgowcarpet 24-Oct-9514.00Good conditionSG37Ann BeechN721 HFR PROPERTY_INSPECTION TABLE
28
27 Property_NoPAddressIDateITimeCommentsStaff_NoSNameCar_Reg PG46 Lawrence Street18-Oct-9410.00Need to replace crockerySG37Anne BeechM231 JGR PG46 Lawrence Street 22-Apr-9509.00In good orderSG14David FordM533 HDR PG46 Lawrence Street 1-Oct-9512.00Damp rot in bathroomSG14David FordN721 HFR PG165 Novar Drive22-Apr-9513.00Replace room carpetSG14David FordM533 HDR PG165 Novar Drive24-Oct-9514.00Good conditionSG37Ann BeechN721 HFR PROPERTY_INSPECTION RELATION First Normal Form (1NF) First Approach Normalize to 1NF – Enter the appropriate property details (non-repeating data) into each row
29
28 First Normal Form (1NF) First Approach The resulting relation is in First Normal Form (1NF) – There is a single value at the intersection of each row and column Property_NoPAddressIDateITimeCommentsStaff_NoSNameCar_Reg PG46 Lawrence Street18-Oct-9410.00Need to replace crockerySG37Anne BeechM231 JGR PG46 Lawrence Street 22-Apr-9509.00In good orderSG14David FordM533 HDR PG46 Lawrence Street 1-Oct-9512.00Damp rot in bathroomSG14David FordN721 HFR PG165 Novar Drive22-Apr-9513.00Replace room carpetSG14David FordM533 HDR PG165 Novar Drive24-Oct-9514.00Good conditionSG37Ann BeechN721 HFR PROPERTY_INSPECTION RELATION
30
29 First Normal Form (1NF) First Approach Identify the candidate keys for the rela-tion – Candidate keys are (Property_No, IDate) and (Staff_No, IDate, ITime) Property_NoPAddressIDateITimeCommentsStaff_NoSNameCar_Reg PG46 Lawrence Street18-Oct-9410.00Need to replace crockerySG37Anne BeechM231 JGR PG46 Lawrence Street 22-Apr-9509.00In good orderSG14David FordM533 HDR PG46 Lawrence Street 1-Oct-9512.00Damp rot in bathroomSG14David FordN721 HFR PG165 Novar Drive22-Apr-9513.00Replace room carpetSG14David FordM533 HDR PG165 Novar Drive24-Oct-9514.00Good conditionSG37Ann BeechN721 HFR PROPERTY_INSPECTION RELATION
31
30 First Normal Form (1NF) First Approach Let’s select (Property_No, IDate) as the primary key Property_NoPAddressIDateITimeCommentsStaff_NoSNameCar_Reg PG46 Lawrence Street18-Oct-9410.00Need to replace crockerySG37Anne BeechM231 JGR PG46 Lawrence Street 22-Apr-9509.00In good orderSG14David FordM533 HDR PG46 Lawrence Street 1-Oct-9512.00Damp rot in bathroomSG14David FordN721 HFR PG165 Novar Drive22-Apr-9513.00Replace room carpetSG14David FordM533 HDR PG165 Novar Drive24-Oct-9514.00Good conditionSG37Ann BeechN721 HFR PROPERTY_INSPECTION RELATION
32
31 First Normal Form (1NF) Second Approach Normalize to 1NF by removing the repeating group to form a new relation Copy the primary key from the main relation to the new relation Identify the primary key for the new relation
33
32 Unnormalized Form (UNF)First Normal Form (1NF) Property_NoPAddressIDateITimeCommentsStaff_NoSNameCar_Reg Which attributes are repeating? First Normal Form (1NF) Second Approach
34
33 First Normal Form (1NF) Second Approach Unnormalized Form (UNF)First Normal Form (1NF) Property_NoPAddressIDateITimeCommentsStaff_NoSNameCar_Reg MOVE
35
34 First Normal Form (1NF) Second Approach Unnormalized Form (UNF)First Normal Form (1NF) Property_NoPAddressIDateITimeCommentsStaff_NoSNameCar_Reg MOVE
36
35 First Normal Form (1NF) Second Approach Unnormalized Form (UNF)First Normal Form (1NF) Property_NoPAddressIDateITimeCommentsStaff_NoSNameCar_Reg Copy the primary key
37
36 First Normal Form (1NF) Second Approach Unnormalized Form (UNF)First Normal Form (1NF) Property_NoPAddressProperty_NoIDateITimeCommentsStaff_NoSNameCar_Reg Identify primary key
38
37 First Normal Form (1NF) Second Approach Unnormalized Form (UNF)First Normal Form (1NF) Property_NoPAddressProperty_NoIDateITimeCommentsStaff_NoSNameCar_Reg Property_No and IDate
39
38 First Normal Form (1NF) Second Approach Unnormalized Form (UNF) First Normal Form (1NF) Property_NoPAddressProperty_NoIDateITimeCommentsStaff_NoSNameCar_Reg Property_NoPAddressProperty_NoIDateITimeCommentsStaff_NoSNameCar_Reg
40
39 Second Normal Form (2NF) Normalization to 2NF is associated with – Composite primary key only! The normalization to 2NF involves – The removal of partial dependencies on the pri-mary key If partial dependencies exist – Remove the dependent attributes to a new relation – Copy their determinant to the new relation
41
40 Second Normal Form First Approach Identify the functional dependen-cies in the Property_Inspection rela-tion Property_NoPAddressIDateITimeCommentsStaff_NoSNameCar_Reg PG46 Lawrence Street18-Oct-9410.00Need to replace crockerySG37Anne BeechM231 JGR PG46 Lawrence Street 22-Apr-9509.00In good orderSG14David FordM533 HDR PG46 Lawrence Street 1-Oct-9512.00Damp rot in bathroomSG14David FordN721 HFR PG165 Novar Drive22-Apr-9513.00Replace room carpetSG14David FordM533 HDR PG165 Novar Drive24-Oct-9514.00Good conditionSG37Ann BeechN721 HFR PROPERTY_INSPECTION RELATION
42
41 Second Normal Form First Approach Property_NoPAddressIDateITimeCommentsStaff_NoSNameCar_Reg PG46 Lawrence Street18-Oct-9410.00Need to replace crockerySG37Anne BeechM231 JGR PG46 Lawrence Street 22-Apr-9509.00In good orderSG14David FordM533 HDR PG46 Lawrence Street 1-Oct-9512.00Damp rot in bathroomSG14David FordN721 HFR PG165 Novar Drive22-Apr-9513.00Replace room carpetSG14David FordM533 HDR PG165 Novar Drive24-Oct-9514.00Good conditionSG37Ann BeechN721 HFR PROPERTY_INSPECTION RELATION Property_No, IDate ITimeCommentsStaff_NoSName Car_Reg Property_NoPAddress Staff_NoSName
43
42 Second Normal Form First Approach Property_NoPAddressIDateITimeCommentsStaff_NoSNameCar_Reg PG46 Lawrence Street18-Oct-9410.00Need to replace crockerySG37Anne BeechM231 JGR PG46 Lawrence Street 22-Apr-9509.00In good orderSG14David FordM533 HDR PG46 Lawrence Street 1-Oct-9512.00Damp rot in bathroomSG14David FordN721 HFR PG165 Novar Drive22-Apr-9513.00Replace room carpetSG14David FordM533 HDR PG165 Novar Drive24-Oct-9514.00Good conditionSG37Ann BeechN721 HFR PROPERTY_INSPECTION RELATION Staff_No, IDate Car_Reg Staff_No, IDate, ITime Property_NoPAddressComments
44
43 Second Normal Form First Approach PAddress is functionally dependent on Pro-perty_No – Remove it to form a new relation with a copy its determinant, Property_No Property_No, IDate ITimeCommentsStaff_NoSNameCar_Reg Property_NoPAddress Staff_NoSName Staff_No, IDate Car_Reg Staff_No, IDate, ITime Property_NoPAddressComments
45
44 Primary Key IDate Staff_No SName ITime PAddress Comments Car_Reg Alternate Key Second Normal Form First Approach Property_No
46
45 Prop(Property_No, Address) Prop_ (Property_No, IDate, ITime, Inspection Comments, Staff_No, SName, Car_Reg) Which is the same as the 1NF generated from the second approach Second Normal Form First Approach The relations have the form:
47
46 Second Normal Form Second Approach First Normal Form (UNF)Second Normal Form (1NF) Property_NoPAddressProperty_NoIDateITimeCommentsStaff_NoSNameCar_Reg Which of the non-key attributes depend on part of the primary key? All the non-key attributes are dependent on both key-attributes
48
47 Second Normal Form Second Approach First Normal Form (UNF)Second Normal Form (1NF) Property_NoPAddressProperty_NoIDateITimeCommentsStaff_NoSNameCar_Reg MOVE MOVE
49
48 Second Normal Form Second Approach First Normal Form (1NF) Second Normal Form (2NF) Property_NoPAddressProperty_NoIDateITimeCommentsStaff_NoSNameCar_RegProperty_NoPAddressProperty_NoIDateITimeCommentsStaff_NoSNameCar_Reg
50
49 Third Normal Form (3NF) Normalization to 3NF involves – The removal of transitive dependencies If a transitive dependency exists – Remove the dependent attributes to a new relation – Copy their determinant to the new relation
51
50 Third Normal Form First Approach Identify the functional dependencies in the Prop and Prop_Inspection relation Property_NoPAddress Property_No, IDate ITimeCommentsStaff_NoSNameCar_Reg Staff_NoSName Staff_No, IDate Car_Reg Staff_No, Idate, ITime Property_NoComments
52
51 Third Normal Form First Approach SName is dependent on Staff_ No – A case of transitive dependency Property_NoPAddress Property_No, IDate ITimeCommentsStaff_NoSNameCar_Reg Staff_NoSName Staff_No, IDate Car_Reg Staff_No, Idate, ITime Property_NoComments
53
52 Third Normal Form First Approach Remove SName with a copy of its deter- minant to a new relation, Staff Property_NoPAddress Property_No, IDate ITimeCommentsStaff_NoSNameCar_Reg Staff_NoSName Staff_No, IDate Car_Reg Staff_No, Idate, ITime Property_NoComments
54
53 Prop(Property_No, PAddress) Prop_ (Property_No, IDate, ITime, Inspection Comments, Staff_No, Car_Reg) Staff(Staff_No, SName) Third Normal Form First Approach The new relations are
55
54 Second Normal Form (2NF)Third Normal Form (3NF) Property_NoPAddressProperty_NoIDateITimeCommentsStaff_NoSNameCar_Reg Third Normal Form Second Approach Which of the non-key attributes depend on other non-key attributes? SName depends on Staff_No
56
55 Third Normal Form Second Approach Second Normal Form (2NF)Third Normal Form (3NF) Property_NoPAddressProperty_NoIDateITimeCommentsStaff_NoCar_RegSName MOVE
57
56 Third Normal Form Second Approach Second Normal Form (2NF)Third Normal Form (3NF) Property_NoPAddressProperty_NoIDateITimeCommentsStaff_NoCar_RegSName Copy the determinant MOVE MOVE
58
57 Third Normal Form Second Approach Second Normal Form (2NF)Third Normal Form (3NF) Property_NoPAddressProperty_NoIDateITimeCommentsStaff_NoCar_RegStaff_NoSName Identify primary key
59
58 Third Normal Form Second Approach Second Normal Form (2NF)Third Normal Form (3NF) Property_NoPAddressProperty_NoIDateITimeCommentsStaff_NoCar_RegStaff_NoSName Staff_No
60
59 Third Normal Form Second Approach Second Normal Form (2NF) Third Normal Form (3NF) Property_NoPAddressProperty_NoIDateITimeCommentsStaff_NoSNameCar_RegProperty_NoPAddressProperty_NoIDateITimeCommentsStaff_NoCar_RegStaff_NoSName
61
60 Boyce-Codd Normal Form (BCNF) A relation is in BCNF if every determinant is a candidate key Identify all the determinants and see if they are candidate keys If they are not, remove them with their dependents to form a new relation
62
61 Boyce-Codd Normal Form (BCNF) The functional dependencies are: Staff_No SName Property_No PAddress Property_No, IDate ITimeCommentsStaff_NoCar_Reg Staff_No, IDate Car_Reg Staff_No, IDate, ITime Property_NoCommentsCar_Reg PROP RELATION STAFF RELATION PROP_INSPECT RELATION
63
62 Boyce-Codd Normal Form (BCNF) Prop and Staff relations are already in BCNF – The determinants are candidate keys Staff_No SName Property_No PAddress Property_No, IDate ITimeCommentsStaff_NoCar_Reg Staff_No, IDate Car_Reg Staff_No, IDate, ITime Property_NoCommentsCar_Reg PROP RELATION STAFF RELATION PROP_INSPECT RELATION
64
63 Staff_No SName Property_No PAddress Property_No, IDate ITimeCommentsStaff_NoCar_Reg Staff_No, IDate Car_Reg Staff_No, IDate, ITime Property_NoCommentsCar_Reg PROP RELATION STAFF RELATION PROP_INSPECT RELATION Boyce-Codd Normal Form (BCNF) Prop_Inspect relation is not in BCNF – (Staff_No, IDate) is not a candidate key
65
64 Boyce-Codd Normal Form (BCNF) Remove (Staff_No, IDate) determinant with its dependents to a new relation, Staff_Car Staff_No SName Property_No PAddress Property_No, IDate ITimeCommentsStaff_NoCar_Reg Staff_No, IDate Car_Reg Staff_No, IDate, ITime Property_NoCommentsCar_Reg PROP RELATION STAFF RELATION PROP_INSPECT RELATION
66
65 Prop (Property_No, PAddress) Inspection (Property_No, IDate, ITime, Comments, Staff_No) Staff (Staff_No, SName) Staff_Car (Staff_No, IDate, Car_Reg) Boyce-Codd Normal Form (BCNF) The final normalized relations are:
67
66 1NF 2NF 3NF BCNF Property_Inspection UNF to BCNF Prop_Inspection Prop_Inspect StaffStaff_CarInspectionProp
68
THE END College of Information Technology
69
68 STUDENT_ADVISOR BCNF A relation is in BCNF if every determinant is a candidate key SID, Major -> Advisor, Maj_GPA Advisor -> Major
70
69 Update anomalies Modification anomaly – Suppose that in Physics, the advisor Hawking is replaced by Einstein. This change must be made in two (or more) rows in the table Insertion anomaly – Suppose we want to insert a row with the information that John advises in Computer Science. This cannot be done until at least one student majoring in Computer Science is assigned John as an advisor Deletion anomaly – If student number 789 withdraws from school, we lose the information that Bach advises in Music
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.