15
Database Normalization beyond 3NF Using BCNF, 4NF, 5NF, and 6NF

Boyce-Codd Normal Form (BCNF) The Boyce-Codd normal form is a step up from the 3NF, but not as restrictive as the 4NF. Boyce-Codd tells us: If attribute

Embed Size (px)

Citation preview

Page 1: Boyce-Codd Normal Form (BCNF) The Boyce-Codd normal form is a step up from the 3NF, but not as restrictive as the 4NF. Boyce-Codd tells us: If attribute

Database Normalization beyond 3NF

Using BCNF, 4NF, 5NF, and 6NF

Page 2: Boyce-Codd Normal Form (BCNF) The Boyce-Codd normal form is a step up from the 3NF, but not as restrictive as the 4NF. Boyce-Codd tells us: If attribute

Boyce-Codd Normal Form (BCNF)The Boyce-Codd normal form is a step up from

the 3NF, but not as restrictive as the 4NF.Boyce-Codd tells us:If attribute Y is functionally dependent on

attribute X, then attribute X must be the primary key.

Page 3: Boyce-Codd Normal Form (BCNF) The Boyce-Codd normal form is a step up from the 3NF, but not as restrictive as the 4NF. Boyce-Codd tells us: If attribute

Most of the time, if a table is in 3NF, it is in BCNF.

When a table contains only 1 candidate key, then the BCNF is the same as 3NF.

Page 4: Boyce-Codd Normal Form (BCNF) The Boyce-Codd normal form is a step up from the 3NF, but not as restrictive as the 4NF. Boyce-Codd tells us: If attribute

Example of 3NF but not BCNF

Branch_Number

Customer_ID (PK)

Loan_ID (PK) Loan_Amount

1 100512 3141 150000

1 122099 3444 25000

2 099344 6501 30000

Consider this table from a bank’s loan database:

Since one loan could have multiple customers, our primary key would have to be Loan ID + Customer ID. Doing that would give us data duplication of the Branch Number and the Loan Amount. Loan ID also determines the Loan Amount, but it isn’t a primary key itself, so this table is not in BCNF.

Page 5: Boyce-Codd Normal Form (BCNF) The Boyce-Codd normal form is a step up from the 3NF, but not as restrictive as the 4NF. Boyce-Codd tells us: If attribute

Loan tables in BCNFTo satisfy BCNF we decompose into two tables:

Branch _Number

Loan_ID (PK) Loan_Amount

1 3141 150000

1 3444 25000

2 6501 30000

and

Customer_ID (PK) Loan_ID (PK)

100512 3141

122099 3444

099344 6501

Page 6: Boyce-Codd Normal Form (BCNF) The Boyce-Codd normal form is a step up from the 3NF, but not as restrictive as the 4NF. Boyce-Codd tells us: If attribute

Fourth Normal Form (4NF)In order for a table to be in 4NF, it must first

be in 3NF and it must not have more than one multivalued dependency. That is, if one value of attribute X will determine multiple values of attribute Y, then there can be no other attribute that has multiple values given that same X value.

Page 7: Boyce-Codd Normal Form (BCNF) The Boyce-Codd normal form is a step up from the 3NF, but not as restrictive as the 4NF. Boyce-Codd tells us: If attribute

Example of 3NF but not 4NFConsider this table from a Ford dealership:

Car_Model (PK)

Engine_Type (PK)

Color (PK)

Mustang 3.7L V6 Red

Mustang 3.7L V6 Blue

Mustang 5.0L V8 Red

Taurus 3.5L V6 Green

Taurus 2.0L Eco Green

You can see that Mustang comes up with multiple values for both Engine and Color. These multivalued dependencies keep the table from being in 4NF.

Page 8: Boyce-Codd Normal Form (BCNF) The Boyce-Codd normal form is a step up from the 3NF, but not as restrictive as the 4NF. Boyce-Codd tells us: If attribute

Car tables in 4NFCar_Model (PK) Engine_Type (PK)

Mustang 3.7L V6

Mustang 5.0L V8

Taurus 3.5L V6

Taurus 2.0L Eco

Car_Model (PK) Color (PK)

Mustang Red

Mustang Blue

Taurus Green

Here, one Model may come up with more than one Engine or Color but the data redundancy is minimized by creating two tables.

Page 9: Boyce-Codd Normal Form (BCNF) The Boyce-Codd normal form is a step up from the 3NF, but not as restrictive as the 4NF. Boyce-Codd tells us: If attribute

Fifth Normal Form (5NF)In order for a table to be in 5NF it must first be

in 4NF and one of these two conditions must apply:

It cannot be broken down into smaller tables

- or -It can be broken down, but all resulting

tables would use the same key.This is the most complete way to remove data redundancy, but it results in more complex databases due to the high number of tables.

Page 10: Boyce-Codd Normal Form (BCNF) The Boyce-Codd normal form is a step up from the 3NF, but not as restrictive as the 4NF. Boyce-Codd tells us: If attribute

Example of 4NF but not 5NFHere is a table about buyers who purchase products from manufacturers to stock in an electronics store:Buyer Manufacturer Product

Steve LG Plasma TVs

Steve LG BluRay Players

Steve Sony LCD TVs

Denise LG BluRay Players

Denise Sony LCD TVs

Denise Sony 3D TVs

If the store decided to start getting LCD TV’s from LG, then you would have to add two rows that have two out of three values identical.

Page 11: Boyce-Codd Normal Form (BCNF) The Boyce-Codd normal form is a step up from the 3NF, but not as restrictive as the 4NF. Boyce-Codd tells us: If attribute

Electronics Tables in 5NFBuyer Manufacture

r

Steve LG

Steve Sony

Denise LG

Denise Sony

Buyer Product

Steve Plasma TVs

Steve BluRay Players

Steve LCD TVs

Denise BluRay Players

Denise LCD TVs

Denise 3D TVs

Manufacturer Product

LG Plasma TVs

LG BluRay Players

Sony LCD TVs

Sony 3D TVs

Now the addition of LCD TVs from LG means one new row in one table.

Page 12: Boyce-Codd Normal Form (BCNF) The Boyce-Codd normal form is a step up from the 3NF, but not as restrictive as the 4NF. Boyce-Codd tells us: If attribute

Sixth Normal Form (6NF)A table is in 6NF only if it is already in 5NF

and every join dependency on that table is trivial.If a table “T” can be broken down into smaller tables and then recreated when needed by using table joins, that is a join dependency on T. A trivial join dependency occurs

when you can only recreate “T” by using table “T” itself.

Page 13: Boyce-Codd Normal Form (BCNF) The Boyce-Codd normal form is a step up from the 3NF, but not as restrictive as the 4NF. Boyce-Codd tells us: If attribute

Example of 5NF but not 6NFHere is a table listing one teacher’s class:

Student_Num

First_Name

Last_Name

Grade

100 Homer Simpson F

101 Stan Smith A

102 Lois Griffin A

103 Cleveland Brown C

This table could be broken down into smaller tables and, if needed, recreated using joins.

Page 14: Boyce-Codd Normal Form (BCNF) The Boyce-Codd normal form is a step up from the 3NF, but not as restrictive as the 4NF. Boyce-Codd tells us: If attribute

Student tables in 6NFStudent_Num First_Name

100 Homer

101 Stan

102 Lois

103 Cleveland

Student_Num Last_Name

100 Simpson

101 Smith

102 Griffin

103 Brown

Student_Num Grade

100 F

101 A

102 A

103 C

These tables are in 6NF, but you can see that they are not really practical.

Page 15: Boyce-Codd Normal Form (BCNF) The Boyce-Codd normal form is a step up from the 3NF, but not as restrictive as the 4NF. Boyce-Codd tells us: If attribute

As you progress from BCNF up to 6NF the restrictions on tables get more and more. The simplicity gained from normalizing the tables may not be worth the added complexity of the database and queries. In most cases, normalizing to the 3NF will be adequate.