Normalization- 3NF

18
Normalization- 3NF 1 Instructor: Mohamed Eltabakh [email protected] Part III

description

Normalization- 3NF. Instructor: Mohamed Eltabakh [email protected]. Part III. Announcements. Homework 2 is due NOW !!! Homework 3 will be out today (Nov. 15) and due on Nov. 22, 8:00AM Midterm on Nov. 22 Until Normalization (Normalization is included) - PowerPoint PPT Presentation

Transcript of Normalization- 3NF

Page 1: Normalization- 3NF

Normalization- 3NF

1

Instructor: Mohamed Eltabakh [email protected]

Part III

Page 2: Normalization- 3NF

Announcements

Homework 2 is due NOW !!!

Homework 3 will be out today (Nov. 15) and due on Nov. 22, 8:00AM

Midterm on Nov. 22 Until Normalization (Normalization is included)

Next lecture is mostly revision + short quiz

2

Page 3: Normalization- 3NF

Third Normal Form: Motivation

There are some situations where BCNF is not dependency preserving

Solution: Define a weaker normal form, called Third Normal Form (3NF) Allows some redundancy (we will see examples later) But all FDs can be checked on individual relations without computing a join There is always a lossless-join, dependency-preserving decomposition

into 3NF

3

Page 4: Normalization- 3NF

Normal Form : 3NF

Relation R is in 3NF if, for every FD in F+ α β,

where α ⊆ R and β ⊆ R, at least one of the following holds:

α → β is trivial (i.e.,β α) ⊆

α is a superkey for R

Each attribute in β-α is part of a candidate key (prime attribute)

4

Page 5: Normalization- 3NF

Testing for 3NF

Use attribute closure to check for each dependency α → β, if α is a superkey

If α is not a superkey, we have to verify if each attribute in (β- α) is contained in a candidate key of R

5

Page 6: Normalization- 3NF

3NF: ExampleLot (ID, county, lotNum, area, price, taxRate)

Candidate key: <county, lotNum>

FDs: county taxRatearea price

Decomposition based on county taxRateLot (ID, county, lotNum, area, price)County (county, taxRate)

6

Is relation Lot in 3NF ? NONO

Are relations Lot and County in 3NF ? Lot is not Lot is not

Page 7: Normalization- 3NF

3NF: Example (Cont’d)Lot (propNo, county, lotNum, area, price)County (county, taxRate)

Candidate key for Lot: <county, lotNum>FDs:

county taxRatearea price

Decomposition based on area priceLot (propNo, county, lotNum, area)County (county, taxRate)Area (area, price)

7

Is every relation in 3NF ? YESYES

Page 8: Normalization- 3NF

Main Idea of the 3NF Decomposition

Use the decomposition algorithm as in BCNF

But to ensure dependency preservation If α β is not preserved, then create relation (α, β) where α is

the key

To ensure the result of decomposition is dependency-preserving and lossless Use the canonical cover in the decomposition

8

Page 9: Normalization- 3NF

Canonical Cover of FDs Canonical Cover (Minimal Cover) = G

Is the smallest set of FDs that produce the same F+

There are no extra attributes in the L.H.S or R.H.S of and dependency in G

Given set of FDs (F) with functional closure F+

Canonical cover of F is the minimal subset of FDs (G), where

G+ = F+

9

Every FD in the canonical cover is needed, otherwise some dependencies are lost

Every FD in the canonical cover is needed, otherwise some dependencies are lost

Page 10: Normalization- 3NF

Example : Canonical Cover

Example : Given F:

A B, ABCD E, EF GH, ACDF EG

Then the canonical cover G: A B, ACD E, EF GH

10

Page 11: Normalization- 3NF

Computing the Canonical Cover

Given a set of functional dependencies F, how to compute the canonical cover G

11Use the next algorithm for this step

Page 12: Normalization- 3NF

Finding Extraneous Attributes

12

Page 13: Normalization- 3NF

Example : Canonical Cover(Lets Check L.H.S) Given F = {A B, ABCD E, EF G, EF H, ACDF EG}

Union Step: {A B, ABCD E, EF GH, ACDF EG}

Test ABCD E Check A:

{BCD}+ = {BCD} A cannot be deleted Check B:

{ACD}+ = {A B C D E} Then B can be deleted

Now the set is: {A B, ACD E, EF GH, ACDF EG}

Test ACD E Check C:

{AD}+ = {ABD} C cannot be deleted Check D:

{AC}+ = {ABC} D cannot be deleted13

Page 14: Normalization- 3NF

Example: Canonical Cover(Lets Check L.H.S-Cont’d) Now the set is: {A B, ACD E, EF GH,

ACDF EG}

Test EF GH Check E:

{F}+ = {F} E cannot be deleted Check F:

{E}+ = {E} F cannot be deleted

Test ACDF EG None of the H.L.S can be deleted

14

Page 15: Normalization- 3NF

Example: Canonical Cover(Lets Check R.H.S) Now the set is: {A B, ACD E, EF GH, ACDF EG}

Test EF GH Check G:

{EF}+ = {E F H} G cannot be deleted Check H:

{EF}+ = {E F G} H cannot be deleted

Test ACDF EG Check E:

{ACDF}+ = {A B C D F E G} E can be deleted

Now the set is: {A B, ACD E, EF GH, ACDF G}

15

Page 16: Normalization- 3NF

Example: Canonical Cover(Lets Check R.H.S-Cont’d) Now the set is: {A B, ACD E, EF GH, ACDF

G}

Test ACDF G Check G:

{ACDF}+ = {A B C D F E G} G can be deleted

Now the set is: {A B, ACD E, EF GH}

16

The canonical cover is:{A B, ACD E, EF GH}

The canonical cover is:{A B, ACD E, EF GH}

Page 17: Normalization- 3NF

Use of Canonical Cover

Used in the decomposition of relations to be in 3NF

The resulting decomposition is lossless and dependency preserving

17

Page 18: Normalization- 3NF

Summary of Normalization Normalization forms

First Normal Form (1NF) BCNF Third Normal Form (2NF) Fourth Normal Form (4NF) – Not covered

Used to ensure the database design is in a good form Decomposing the relation according to functional dependencies

18