Top Banner
by Andrew Yee
21

By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Jan 01, 2016

Download

Documents

Moses Reynolds
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

by Andrew Yee

Page 2: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Why 4NF?

• Performance–We want database to take up

less space.

Page 3: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Why 4NF?

• To eliminate the possibility for data anomalies.

Page 4: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Why 4NF?

• To reduce the need for:–inserts, –updates –deletes

Page 5: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Normal Forms ComparisonNormal Form # What you need?

1NF Remove repeating Groups

2NF Remove Partial Dependencies

3NF Remove Transitive Dependencies

BCNF Make sure every determinant is a Candidate Key

4NF Remove nontrivial Multi-Valued Dependencies (MVD)

Page 6: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Non-Trival Multi-Valued Dependencies (MVD)

• Assume X is the Superkey–“Superkey” still depends on FD’s only.

• Y is not a subset of X• X and Y are not, together, all the

attributes.

Page 7: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Recap of 4NF Definition

• No non-trivial multi-valued dependencies- Except on superset of a candidate key- Multi-valued dependencies are functional

dependencies.

• Table must be in BCNF

Page 8: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Recap of 4NF Definition

• No Duplications

• Table must be in BCNF

Page 9: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Example to get 4NF

• Assume the table is in BCNF• The town, Region, and District together form the candidate

key.

From Reference #1

Page 10: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Example to get 4NF

• Decomposed into two tables

From Reference #1

Page 11: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Example 2: Is it in 3NF or BCNF?Restaurant Pizza Variety Delivery Area

A1 Pizza Thick Crust Springfield

A1 Pizza Thick Crust Shelbyville

A1 Pizza Thick Crust Capital City

A1 Pizza Stuffed Crust Springfield

A1 Pizza Stuffed Crust Shelbyville

A1 Pizza Stuffed Crust Capital City

Elite Pizza Thin Crust Capital City

Elite Pizza Stuffed Crust Capital City

Vincenzo's Pizza Thick Crust Springfield

Vincenzo's Pizza Thick Crust Shelbyville

Vincenzo's Pizza Thin Crust Springfield

Vincenzo's Pizza Thin Crust Shelbyville

Pizza Delivery

From Reference #2

Page 12: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Example 2: Is it in 3NF or BCNF?

• The table has no non-key attributes because its only key is {Restaurant, Pizza Variety, Delivery Area}.

• The answer is BCNF.

From Reference #2

Page 13: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Example 2: Is it in 4NF?Restaurant Pizza Variety Delivery Area

A1 Pizza Thick Crust Springfield

A1 Pizza Thick Crust Shelbyville

A1 Pizza Thick Crust Capital City

A1 Pizza Stuffed Crust Springfield

A1 Pizza Stuffed Crust Shelbyville

A1 Pizza Stuffed Crust Capital City

Elite Pizza Thin Crust Capital City

Elite Pizza Stuffed Crust Capital City

Vincenzo's Pizza Thick Crust Springfield

Vincenzo's Pizza Thick Crust Shelbyville

Vincenzo's Pizza Thin Crust Springfield

Vincenzo's Pizza Thin Crust Shelbyville

Pizza Delivery

From Reference #2

Page 14: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Example 2: Is it in 4NF?

• If we assume, that pizza varieties offered by a restaurant are not affected by delivery area, then it does not meet 4NF.

• The answer is NO.

From Reference #2

Page 15: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Why not in 4NF?Restaurant Pizza Variety Delivery Area

A1 Pizza Thick Crust Springfield

A1 Pizza Thick Crust Shelbyville

A1 Pizza Thick Crust Capital City

A1 Pizza Stuffed Crust Springfield

A1 Pizza Stuffed Crust Shelbyville

A1 Pizza Stuffed Crust Capital City

Elite Pizza Thin Crust Capital City

Elite Pizza Stuffed Crust Capital City

Vincenzo's Pizza Thick Crust Springfield

Vincenzo's Pizza Thick Crust Shelbyville

Vincenzo's Pizza Thin Crust Springfield

Vincenzo's Pizza Thin Crust Shelbyville

Pizza Delivery

From Reference #2

Two Non-trivial: MVD

Page 16: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Why not in 4NF?

• The table has two non-trivial multivalued dependencies on the {Restaurant} attribute (which is not a superkey).

• The dependencies are:– {Restaurant} →→ {Pizza Variety}– {Restaurant} →→ {Delivery Area}

From Reference #2

Page 17: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

How to “fix it” (4NF)?Restaurant Pizza Variety Delivery Area

A1 Pizza Thick Crust Springfield

A1 Pizza Thick Crust Shelbyville

A1 Pizza Thick Crust Capital City

A1 Pizza Stuffed Crust Springfield

A1 Pizza Stuffed Crust Shelbyville

A1 Pizza Stuffed Crust Capital City

Elite Pizza Thin Crust Capital City

Elite Pizza Stuffed Crust Capital City

Vincenzo's Pizza Thick Crust Springfield

Vincenzo's Pizza Thick Crust Shelbyville

Vincenzo's Pizza Thin Crust Springfield

Vincenzo's Pizza Thin Crust Shelbyville

Pizza Delivery

From Reference #2

Two Non-trivial: MVD

Page 18: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

How to “fix it” (4NF)?

From Reference #2

Restaurant Pizza Variety

A1 Pizza Thick Crust

A1 Pizza Stuffed Crust

Elite Pizza Thin Crust

Elite Pizza Stuffed Crust

Vincenzo's Pizza Thick Crust

Vincenzo's Pizza Thin Crust

Restaurant Delivery Area

A1 Pizza Springfield

A1 Pizza Shelbyville

A1 Pizza Capital City

Elite Pizza Capital City

Vincenzo's Pizza Springfield

Vincenzo's Pizza Shelbyville

Varieties By RestaurantDelivery Areas By Restaurant

No Duplications among rows! Yay!

Page 19: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Practice Example1. Is this 3NF or BCNF?2. Is this 4NF? 3. If not, what are the decomposed tables in 4NF?

Restaurant Pizza Variety Delivery Area

A1 Pizza Thick Crust Springfield

A1 Pizza Thick Crust Shelbyville

A1 Pizza Thick Crust Capital City

A2 Pizza Stuffed Crust Springfield

A2 Pizza Stuffed Crust Shelbyville

Pizza Delivery

Page 20: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

Practice Example (Answer)1. BCNF 2. NO 3. See Below

Restaurant Pizza Variety

A1 Pizza Thick Crust

A1 Pizza Stuffed Crust

A2 Pizza Stuffed Crust

Restaurant Delivery Area

A1 Pizza Springfield

A1 Pizza Shelbyville

A1 Pizza Capital City

A2 Pizza Springfield

A2 Pizza Shelbyville

Varieties By Restaurant Delivery Areas By Restaurant

No Duplications among rows! Yay!

Page 21: By Andrew Yee. Why 4NF? Performance – We want database to take up less space.

References1. Website: Database Design: 4th and 5th Normal Forms « Tod means Fox

URL: http://blog.todmeansfox.com/2007/12/04/database-design-4th-and-5th-normal-forms/

2. Website: Fourth normal form - Wikipedia, the free encyclopediaURL: http://en.wikipedia.org/wiki/Fourth_normal_form