Download presentation
Presentation is loading. Please wait.
Published byΖηναις Βλαχόπουλος Modified over 6 years ago
1
CSCI 2141 – Intro to Database Systems Database Normalization
3NF and BCNF
2
Converting to 3NF Tables are in 3NF (Third Normal Form) when
They are in 2NF, and They have no transitive dependencies Transitive dependency: An attribute functionally depends on another non-key attribute Converting to 3NF Ensure that the tables are in 2NF Make new tables to eliminate transitive dependencies Reassign corresponding dependent attributes
3
Example Identify all dependencies.
Identify which normal form the table is in. Convert to the third normal form (3NF). INV_NUM INV_DATE INV_AMOUNT CUS_NUM CUS_ADDRESS CUS_PHONE
4
Example – Solution Dependencies are shown in figure below.
Table is in 1NF as all attributes show functional dependency on the PK Table is also in 2NF as the PK is not composite, and there is no candidate key. There are no partial dependencies INV_NUM INV_DATE INV_AMOUNT CUS_NUM CUS_ADDRESS CUS_PHONE Original table Transitive Dependencies
5
Example – Solution Eliminating transitive dependencies result in the following tables Each of the table above is in 3NF INV_NUM INV_DATE INV_AMOUNT CUS_NUM New Tables CUS_NUM CUS_ADDRESS CUS_PHONE
6
Practice Exercise 5 Using the INVOICE table structure shown below:
Write the relational schema, and draw its dependency diagram identifying all dependencies (Assume there are no repeating groups and invoice number references more than one product) Remove all partial dependencies, write the relational schema, and draw the new dependency diagrams. Identify the normal forms for each table structure you create Remove all transitive dependencies, write the relational schema, and draw the new dependency diagrams. Also, draw the ERD Attribute Name Sample Value INV_NUM 211347 211348 211349 PROD_NUM AA-E3422QW QD X RU G GH P SALE_DATE 15-Jan-2016 16-Jan-2016 PROD_LABEL Rotary sander 0.25-in. drill bit Band saw Power drill VEND_CODE 211 309 157 VEND_NAME NeverFail, Inc. BeGood, Inc. ToughGo, Inc. QUANT_SOLD 1 8 2 PROD_PRICE $49.95 $3.45 $39.99 $87.75 any invoice number may reference more than one product.
7
Practice Exercise 5 – Solution
Relational schema and dependency diagram are as shown
8
Practice Exercise 5 – Solution
Relational schema, and tables with partial dependencies removed (at least 2NF) are as shown below: We can identify the sale date using the invoice number, but cannot identify the invoice number from the sale date as many invoices are made on any given day
9
Practice Exercise 5 – Solution
Relational schema, and tables with transitive dependencies removed (3NF) are as shown below:
10
Practice Exercise 5 – Solution
ERD is shown below: the dependency diagrams cannot show the nature (1:1, 1:M, M:N) of the relationships, the ER Diagrams remain crucial to the design effort. Complex design is impossible to produce successfully without some form of modeling
11
Boyce-Codd Normal Form (BCNF)
BCNF is a special case of 3NF Table is in BCNF when every determinant in the table is a candidate key When a table in 3NF has only one candidate key, it is also in BCNF How can a table be in 3NF but not in BCNF? So in order for the BCNF to be violated, a table must have more than one candidate key, or at least one candidate key other than the primary key When a table has overlapping candidate keys, it may or may not be in BCNF
12
Boyce-Codd Normal Form (BCNF)
Consider the following table: Its candidate keys are given to be: A+B A+C Identify its dependencies and determinants C->B, note that C is a key or prime attribute (or part of a candidate key), and not a non-key attribute
13
Boyce-Codd Normal Form (BCNF)
Is the table in 1NF? Key (or prime) attributes are defined All non-key attributes are determined by the key Is the table in 2NF? It is in 1NF No partial dependencies Is the table in 3NF It is in 2NF No transitive dependencies Note that C → B is not transitive The table is in 3NF, however, it is not in BCNF Note that here, key refers to both the PK and the Candidate key Transitive dependency is defined as the dependency of a non-key attribute on another non-key attribute
14
Boyce-Codd Normal Form (BCNF)
The dependency C → B means that effectively, C is a superset of B In order to convert to BCNF, change the PK to A+C Can you identify the normal form for the table below? 1NF
15
Boyce-Codd Normal Form (BCNF)
16
BCNF - Example Table below reflects the following conditions:
A class represents one section of a course (that may have many) A student can take many classes A staff member can teach many classes, but one class is taught by one staff member E.g. student 125 has taken 2 classes, getting A and C grades respectively Also, using Staff_ID, we cannot determine class_code as one staff may teach many classes (even for the same course), but knowing class_code, we can determine staff_id, hence Class_Code -> Staff_ID
17
BCNF - Example
18
BCNF – Exercise Convert the dependency diagram given below to 3NF
Determine if the 3NF is also in BCNF If not, convert to BCNF
19
Exercise – Solution Step 1: Removing partial dependencies, we get:
3 NF C E F D B 2 NF Transitive dependency G Not a transitive dependency
20
Exercise – Solution Step 2: Removing transitive dependencies, we get:
21
Exercise – Solution Step 3: Converting to BCNF Change the PK to A+C
Table is now in 1NF due to a partial dependency C →B Convert table to 3NF All tables are in 3NF and BCNF
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.