normalization l.
Skip this Video
Loading SlideShow in 5 Seconds..
Normalization PowerPoint Presentation
Download Presentation

Loading in 2 Seconds...

play fullscreen
1 / 22

Normalization - PowerPoint PPT Presentation

  • Uploaded on

Normalization. Anomalies Boyce-Codd Normal Form 3 rd Normal Form. Source: Slides by Jeffrey Ullman. Anomalies. Goal of relational schema design is to avoid anomalies and redundancy. Update anomaly : one occurrence of a fact is changed, but not all occurrences.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Normalization' - libitha

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript



Boyce-Codd Normal Form

3rd Normal Form

Source: Slides by Jeffrey Ullman

  • Goal of relational schema design is to avoid anomalies and redundancy.
    • Update anomaly: one occurrence of a fact is changed, but not all occurrences.
    • Deletion anomaly : a valid fact is lost when a tuple is deleted.
example of bad design
Example of Bad Design

Consumers(name, addr, candiesLiked, manf, favCandy)

name addr candiesLiked manf favCandy

Janeway Voyager Twizzlers Hershey Smarties

Janeway ??? Smarties Pete’s ???

Spock Enterprise Twizzlers ??? Twizzlers

Data is redundant, because each of the ???’s can be figured

out by using the FD’s name -> addr favCandy and

candiesLiked -> manf.

this bad design also exhibits anomalies
This Bad Design AlsoExhibits Anomalies

name addr candiesLiked manf favCandy

Janeway Voyager Twizzlers Hershey Smarties

Janeway Voyager Smarties Nestle Smarties

Spock Enterprise Twizzlers Hershey Twizzlers

  • Update anomaly: if Janeway is transferred to Intrepid,
  • will we remember to change each of her tuples?
  • Deletion anomaly: If nobody likes Twizzlers, we lose track
  • of the fact that Hershey manufactures Twizzlers.
boyce codd normal form
Boyce-Codd Normal Form
  • We say a relation R is in BCNF if whenever X ->Ais a nontrivial FD that holds in R, X is a superkey.
    • Remember:nontrivial means A is not a member of set X.
    • Remember, a superkey is any superset of a key (not necessarily a proper superset).

Consumers(name, addr, candiesLiked, manf, favCandy)

FD’s: name->addr favCandy, candiesLiked->manf

  • Only key is {name, candiesLiked}.
  • In each FD, the left side is not a superkey.
  • Any one of these FD’s shows, Consumers is not in BCNF
another example
Another Example

Candies(name, manf, manfAddr)

FD’s: name->manf, manf->manfAddr

  • Only key is {name} .
  • name->manf does not violate BCNF, but manf->manfAddr does.
decomposition into bcnf
Decomposition into BCNF
  • Given: relation R with set of FD’s F.
  • Compute keys for R (sets of attributes that functionally determine all other attributes)
  • Look among the given FD’s for a BCNF violation X ->B.
    • If any FD following from F violates BCNF, then there will surely be an FD in F itself that violates BCNF.
  • Compute X+.
    • Won't be all attributes, or else X would be a superkey and X ->B would not be a violation
decompose r using x b
Decompose R Using X -> B
  • Replace R by relations R1 and R2 with schemas:
    • R1 : X+ (all attributes "reachable" from X)
    • R2 : R – (X+ – X ) (X plus all attributes not "reachable" from X)
  • Project given FD’s F onto the two new relations (ignore FD's containing attributes no longer in the new relation).
  • Check if procedure must be repeated with R1and/or R2.
decomposition picture
Decomposition Picture








Consumers(name, addr, candiesLiked, manf, favCandy)

F = name->addr, name -> favCandy, candiesLiked->manf

  • Pick BCNF violation name->addr.
  • Close the left side: {name}+ = {name, addr, favCandy}.
  • Decomposed relations:
    • Consumers1(name, addr, favCandy)
    • Consumers2(name, candiesLiked, manf)
example continued
Example, Continued
  • We are not done; we need to check Consumers1 and Consumers2 for BCNF.
  • Projecting FD’s is easy here.
  • For Consumers1(name, addr, favCandy), relevant FD’s are name->addr and name->favCandy.
    • Thus, {name} is the only key and Consumers1 is in BCNF.
example continued13
Example, Continued
  • For Consumers2(name, candiesLiked, manf), the only FD is candiesLiked -> manf, and the only key is {name, candiesLiked}.
    • Violation of BCNF.
  • candiesLiked+ = {candiesLiked, manf}, so we decompose Consumers2 into:
    • Consumers3(candiesLiked, manf)
    • Consumers4(name, candiesLiked)
example concluded
Example, Concluded
  • The resulting decomposition of Consumers :

Consumers1(name, addr, favCandy)

Consumers3(candiesLiked, manf)

Consumers4(name, candiesLiked)

  • Notice: Consumers1 tells us about consumers, Consumers3 tells us about candies, and Consumers4 tells us the relationship between consumers and the candies they like.
third normal form motivation
Third Normal Form - Motivation
  • There is one structure of FD’s that causes trouble when we decompose.
  • AB ->C and C ->B.
    • Example: A = street address, B = city,

C = zip code.

  • There are two keys, {A,B } and {A,C }.
    • Think about why.
  • C ->B is a BCNF violation (why?), so we must decompose into AC, BC.
we cannot enforce fd s
We Cannot Enforce FD’s
  • The problem is that if we use AC and BC as our database schema, we cannot enforce the FD AB ->C by checking FD’s in these decomposed relations.
  • Example with A = street, B = city, and C = zip on the next slide.
an unenforceable fd
An Unenforceable FD
  • Suppose we have relation Addr with FD's:
    • street city -> zip
    • zip -> city
  • Keys are {street, city} and {street, zip}
  • After decomposing, we have relations
    • Addr1(street,zip) with no FD (!)
    • Addr2(city,zip) with FD zip -> city
  • Consider instances on next slide…
an unenforceable fd cont d

Join tuples with equal zip codes.

street city zip

545 Tech Sq. Cambridge 02138

545 Tech Sq. Cambridge 02139

An Unenforceable FD (cont'd)



street zip

545 Tech Sq. 02138

545 Tech Sq. 02139

city zip

Cambridge 02138

Cambridge 02139

Although no FD’s were violated in the decomposed relations,

FD street city -> zip is violated by the database as a whole.

3nf lets us avoid this problem
3NF Lets Us Avoid This Problem
  • 3rd Normal Form (3NF) modifies the BCNF condition so we do not have to decompose in this problem situation.
  • An attribute is prime if it is a member of any key.
  • X ->Aviolates 3NF if and only if X is not a superkey, and also A is not prime.
  • In our problem situation with FD’s AB ->C and C ->B, we have keys AB and AC.
  • Thus A, B, and C are each prime.
  • Although C ->B violates BCNF, it does not violate 3NF.
  • So no need to decompose.
what 3nf and bcnf give you
What 3NF and BCNF Give You
  • There are two important properties of a decomposition:
    • Recovery: it should be possible to project the original relations onto the decomposed schema, and then reconstruct the original.
    • Dependency Preservation : it should be possible to check in the projected relations whether all the (original) given FD’s are satisfied.
3nf and bcnf continued
3NF and BCNF, Continued
  • We can get (1) with a BCNF decomposition.
    • Explanation needs to wait for relational algebra.
  • We can get both (1) and (2) with a 3NF decomposition.
  • But we can’t always get (1) and (2) with a BCNF decomposition.
    • street-city-zip is an example.