Normalization Copyright © 1999 Patrick McDermott College of Alameda [email protected].

15
Normalization Copyright © 1999 Patrick McDermott College of Alameda [email protected]

Transcript of Normalization Copyright © 1999 Patrick McDermott College of Alameda [email protected].

Page 1: Normalization Copyright © 1999 Patrick McDermott College of Alameda pmcdermott@peralta.edu.

NormalizationCopyright © 1999 Patrick McDermott

College of [email protected]

Page 2: Normalization Copyright © 1999 Patrick McDermott College of Alameda pmcdermott@peralta.edu.

• Eliminate the Redundancy• The “Who Cares?” Test• Ben Franklin, DBA

John McCoyHatter

Fine Hats Made and Sold

Redundant & Superfluous

Page 3: Normalization Copyright © 1999 Patrick McDermott College of Alameda pmcdermott@peralta.edu.

For Each and Every• Not Redundant• At the Right level• Passes The “Who Cares?” Test• Usual goal is 3NF, though there are others

– BCNF: Boyce/Codd NF– 4NF– 5NF

I Saw the Figure 5 in GoldCharles Demuthc. 1928

Page 4: Normalization Copyright © 1999 Patrick McDermott College of Alameda pmcdermott@peralta.edu.

Functional Dependencies• If you know Key x, you can determine

attribute Y

x Y

Page 5: Normalization Copyright © 1999 Patrick McDermott College of Alameda pmcdermott@peralta.edu.

1NF (First Normal Form)

2NF (Second Normal Form

3NF (Third Normal Form

BCNF (Boyce-Codd NF)

4NF (Fourth Normal Form)

5NF (Fifth Normal Form)

Normal Forms

Page 6: Normalization Copyright © 1999 Patrick McDermott College of Alameda pmcdermott@peralta.edu.

Primary KeyUnique

– At any time– Across Time– Forever & Always

Always– Mandatory– Even if optional, it’s mandatory.– You never want anything important hidden!

Page 7: Normalization Copyright © 1999 Patrick McDermott College of Alameda pmcdermott@peralta.edu.

1NF

1. Reduce entities to first normal form (1NF) by removing repeating or multivalued attributes to another, child entity.

First normal form (1NF) requires that each entity have a fixed number of attributes, each with a unique meaning and name. You achieve first normal form in by removing to a child entity any repeating or multivalued attributes, thereby organizing the data as “flat” structures.

Page 8: Normalization Copyright © 1999 Patrick McDermott College of Alameda pmcdermott@peralta.edu.

2NF

2. Reduce 1NF entities to second normal form (2NF) by removing attributes that are not dependent on the whole primary key.

Second normal form (2NF) requires that each nonkey attribute in a first normal form entity depend on the entire primary key. You achieve second normal form by removing to a parent entity any attributes dependent on only a subset of the primary key.

Page 9: Normalization Copyright © 1999 Patrick McDermott College of Alameda pmcdermott@peralta.edu.

Trivial 2NF• If all the columns in the table are part or the

key• It has a single column primary key

• Can add a synthetic key to get to 2NF• BUT there will be a transitive dependency,

you’ll need to get rid of for 3NF

Page 10: Normalization Copyright © 1999 Patrick McDermott College of Alameda pmcdermott@peralta.edu.

3NF3. Reduce 2NF entities to third normal form

(3NF) by removing to a parent entity attributes that depend on other, nonkey attributes.

Third normal form (3NF) requires that each nonkey attribute within a second normal form entity depend on the entire primary key and nothing other than the primary (and alternate) keys. You achieve third normal form by removing to a parent entity any attributes exhibiting transitive dependencies (i.e., nonkey attributes that depend on other nonkey attributes, where these other attributes are not alternate keys).

Page 11: Normalization Copyright © 1999 Patrick McDermott College of Alameda pmcdermott@peralta.edu.

1NF-3NF• First NF: Each item is Atomic

– No Repeating Fields

• Second NF: In 1NF and Each item relates to the Key

• Third NF: In 2NF and No item is a fact about another item

The KeyThe whole Key

And nothing but the KeySo help me Codd

Page 12: Normalization Copyright © 1999 Patrick McDermott College of Alameda pmcdermott@peralta.edu.

Fog Warning“In nearly all logical data models, reaching

third normal form is sufficient and is equivalent to reaching Boyce/Codd normal form, fourth normal form, and fifth normal form. Thus, if you are confused about levels beyond third normal form, do not worry! The highest three levels are minutely more desirable and need be attempted only by the advanced design analyst.”—Fleming & von Halle, Handbook of Relational Database Design

The Fog WarningWinslow Homerc. 1885

Page 13: Normalization Copyright © 1999 Patrick McDermott College of Alameda pmcdermott@peralta.edu.

BCNF3½ Reduce 3NF entities to Boyce/Codd normal

form (BCNF) by ensuring that they are in 3NF for any feasible choice of candidate key as primary key.

Boyce/Codd normal form (BCNF) requires that all attributes depend on only the full candidate keys (primary and alternate keys) and do not depend on any subset of a candidate key. You achieve Boyce/Codd normal form by assuring that an entity is in third normal form for any feasible choice of candidate key as primary key. (For many logical data models, third normal form is equivalent to Boyce/Codd normal form.)

Page 14: Normalization Copyright © 1999 Patrick McDermott College of Alameda pmcdermott@peralta.edu.

4NF4. Reduce BCNF entities to fourth normal form

(4NF) by removing any independently multivalued components of the primary key to two new parent entities. Retain the original (now child) entity only if it contains other, nonkey attributes.

Fourth normal form (4NF) requires that the primary key of a third normal form entity contain no independently multivalued attributes. You achieve fourth normal form by removing any pair of such attributes to two new parent entities. (Many data analysts attain fourth normal form instinctively in the process of achieving third normal form.)

Page 15: Normalization Copyright © 1999 Patrick McDermott College of Alameda pmcdermott@peralta.edu.

5NF—a.k.a Projection/Join PJNF5. Reduce 4NF entities to fifth normal form

(5NF) by removing pairwise cyclic dependencies (appearing within composite primary keys with three or more component attributes) to three or more new parent entities.

Fifth normal form (5NF) requires that the primary key of a fourth normal form entity contain no pairwise cyclic redundancies. A cyclic redundancy occurs in a composite primary key of three or more attributes (A, B, C) if whenever entity occurrences (A1, B1, C2), (A2, B1, C1) and (A1, B2, C1) occur, then (A1, B1, C1) also is present.