Docsity

Normalization - Database Systems - Lecture Slides, Slides of Database Management Systems (DBMS)

Partial preview of the text

Download Normalization - Database Systems - Lecture Slides and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

Normalization

Anomalies

Boyce-Codd Normal Form

3 rd^ Normal Form

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.
  • Deletion anomaly : a valid fact is lost when a tuple is deleted.

This Bad Design Also

Exhibits Anomalies

4

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.

Problem & Solution

  • Conceptual modeling unnaturally puts attributes of two different entity sets in same relation schema
  • Use decompositions to break up schema involving such an “unhappy union” into several relation schemas
  • Must do this decomposition carefully:
    • Various normal forms have been proposed for relations
    • If a schema is in one of these normal forms, then we now that certain kinds of problems do not occur

When to Decompose?

  • If you frequently want the full information

available in instances of the original relation,

don’t decompose

  • Expensive to reconstruct original information
  • Instead, put up with the storage redundancy and put extra checks in apps to avoid anomalies

Boyce-Codd Normal Form

  • We say a relation R is in BCNF if whenever X -

> A is 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).

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.

Properties of BCNF

  • If a relation is in BCNF, then every attribute of every tuple records a piece of information that cannot be inferred, using FD’s, from any other information in the relation - Eliminates redundancy
  • If a relation is not in BCNF, there is always a lossless- join decomposition into a collection of BCNF relations - But may not be a dependency-preserving decomposition

Decompose R Using X -> B

  • Replace R by relations R 1 and R 2 with schemas:
    • R 1 : X +^ (all attributes "reachable" from X )
    • R 2 : 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 R (^1) and/or R 2.

Decomposition Picture

14

R - X +^ X X +^ - X

R 2

R 1

R

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, 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)

BCNF Decomposition Not Unique

  • Suppose several dependencies violate BCNF.
  • Depending on which is used to guide the next

decomposition, might get different collections of decomposed relations

  • Normalization theory does not help us decide among

alternatives: designer must consider alternatives and choose based on semantics of the application

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.