21
by Andrew Yee

Stuff iThink that will be on the Quiz/Midterm

  • Upload
    ulema

  • View
    27

  • Download
    2

Embed Size (px)

DESCRIPTION

Stuff iThink that will be on the Quiz/Midterm. Fourth Normal Form. by Andrew Yee. Why 4NF?. Performance We want database to take up less space. Why 4NF?. To eliminate the possibility for data anomalies. Why 4NF?. To reduce the need for: inserts, updates deletes. - PowerPoint PPT Presentation

Citation preview

Page 1: Stuff  iThink that will be on the Quiz/Midterm

by Andrew Yee

Page 2: Stuff  iThink that will be on the Quiz/Midterm

Why 4NF?

• Performance–We want database to take up

less space.

Page 3: Stuff  iThink that will be on the Quiz/Midterm

Why 4NF?

• To eliminate the possibility for data anomalies.

Page 4: Stuff  iThink that will be on the Quiz/Midterm

Why 4NF?

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

Page 5: Stuff  iThink that will be on the Quiz/Midterm

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: Stuff  iThink that will be on the Quiz/Midterm

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: Stuff  iThink that will be on the Quiz/Midterm

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: Stuff  iThink that will be on the Quiz/Midterm

Recap of 4NF Definition

• No Duplications

• Table must be in BCNF

Page 9: Stuff  iThink that will be on the Quiz/Midterm

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: Stuff  iThink that will be on the Quiz/Midterm

Example to get 4NF

• Decomposed into two tables

From Reference #1

Page 11: Stuff  iThink that will be on the Quiz/Midterm

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: Stuff  iThink that will be on the Quiz/Midterm

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: Stuff  iThink that will be on the Quiz/Midterm

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: Stuff  iThink that will be on the Quiz/Midterm

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: Stuff  iThink that will be on the Quiz/Midterm

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: Stuff  iThink that will be on the Quiz/Midterm

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: Stuff  iThink that will be on the Quiz/Midterm

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: Stuff  iThink that will be on the Quiz/Midterm

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: Stuff  iThink that will be on the Quiz/Midterm

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: Stuff  iThink that will be on the Quiz/Midterm

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: Stuff  iThink that will be on the Quiz/Midterm

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