1 Normalization Anomalies Boyce-Codd Normal Form 3 rd Normal Form Source: Slides by Jeffrey Ullman.

Slides:



Advertisements
Similar presentations
1 Lecture 7 Design Theory for Relational Databases (part 1) Slides based on
Advertisements

Lecture 21 CS 157 B Revision of Midterm3 Prof. Sin-Min Lee.
4NF and 5NF Prof. Sin-Min Lee Department of Computer Science.
1 Design Theory for Relational Databases Functional Dependencies Decompositions Normal Forms.
1 Loss-Less Joins. 2 Decompositions uDependency-preservation property: enforce constraints on original relation by enforcing some constraints on resulting.
Chapter 3 Notes. 3.1 Functional Dependencies A functional dependency is a statement that – two tuples of a relation that agree on some particular set.
Database Management Systems Chapter 3 The Relational Data Model (II) Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
Functional Dependencies, Normalization Rose-Hulman Institute of Technology Curt Clifton.
1 Normalization. 2 Normal Forms v If a relation is in a certain normal form (BCNF, 3NF etc.), it is known that certain kinds of redundancies are avoided/minimized.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 227 Database Systems I Design Theory for Relational Databases.
1 Multivalued Dependencies Fourth Normal Form Source: Slides by Jeffrey Ullman.
1 The Relational Data Model Functional Dependencies.
1 Multivalued Dependencies Fourth Normal Form. 2 Definition of MVD uA multivalued dependency (MVD) on R, X ->->Y, says that if two tuples of R agree on.
1 Normalization Anomalies Boyce-Codd Normal Form 3 rd Normal Form Source: Slides by Jeffrey Ullman.
1 Multivalued Dependencies Fourth Normal Form Sources: Slides by Jeffrey Ullman book by Ramakrishnan & Gehrke.
1 Functional Dependencies Meaning of FD’s Keys and Superkeys Inferring FD’s.
1 Functional Dependencies Meaning of FD’s Keys and Superkeys Inferring FD’s Source: slides by Jeffrey Ullman.
The principal problem that we encounter is redundancy, where a fact is repeated in more than one tuple. Most common cause: attempts to group into one relation.
Winter 2002Arthur Keller – CS 1804–1 Schedule Today: Jan. 15 (T) u Normal Forms, Multivalued Dependencies. u Read Sections Assignment 1 due. Jan.
1 Multivalued Dependencies Fourth Normal Form. 2 A New Form of Redundancy uMultivalued dependencies (MVD’s) express a condition among tuples of a relation.
1 Normalization Anomalies Boyce-Codd Normal Form 3 rd Normal Form.
Schema Refinement and Normalization Nobody realizes that some people expend tremendous energy merely to be normal. Albert Camus.
1 Functional Dependencies Why FD's Meaning of FD’s Keys and Superkeys Inferring FD’s Source: slides by Jeffrey Ullman.
Normalization. FarkasCSCE 5202 Reading Assignments  Database Systems The Complete Book: Chapters 3.6, 3.7, 3.8  Following lecture slides are modified.
Fall 2001Arthur Keller – CS 1804–1 Schedule Today Oct. 4 (TH) Functional Dependencies and Normalization. u Read Sections Project Part 1 due. Oct.
1 Normalization Anomalies Boyce-Codd Normal Form 3 rd Normal Form.
1 Lecture 7: Schema refinement: Normalisation
1 Design Theory for Relational Databases Functional Dependencies Decompositions Normal Forms.
Decompositions uDo we need to decompose a relation? wSeveral normal forms for relations. If schema in these normal forms certain problems don’t.
Database Management Systems Chapter 3 The Relational Data Model (III) Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
Databases 1 Seventh lecture. Topics of the lecture Extended relational algebra Normalization Normal forms 2.
1 Normalization Anomalies Boyce-Codd Normal Form 3 rd Normal Form.
Normalization Goal = BCNF = Boyce-Codd Normal Form = all FD’s follow from the fact “key  everything.” Formally, R is in BCNF if for every nontrivial FD.
Schema Refinement and Normalization. Functional Dependencies (Review) A functional dependency X  Y holds over relation schema R if, for every allowable.
Database Normalization.
CS143 Review: Normalization Theory Q: Is it a good table design? We can start with an ER diagram or with a large relation that contain a sample of the.
SCUJ. Holliday - coen 1784–1 Schedule Today: u Normal Forms. u Section 3.6. Next u Relational Algebra. Read chapter 5 to page 199 After that u SQL Queries.
BCNF & Lossless Decomposition Prof. Sin-Min Lee Department of Computer Science.
Functional Dependencies. FarkasCSCE 5202 Reading and Exercises Database Systems- The Complete Book: Chapter 3.1, 3.2, 3.3., 3.4 Following lecture slides.
IST 210 Normalization 2 Todd Bacastow IST 210. Normalization Methods Inspection Closure Functional dependencies are key.
1 Design Theory for Relational Databases Functional Dependencies Decompositions Normal Forms.
Third Normal Form (3NF) Zaki Malik October 23, 2008.
1 CSE 480: Database Systems Lecture 18: Normal Forms and Normalization.
1 Multivalued Dependencies Fourth Normal Form Reasoning About FD’s + MVD’s.
1 Multivalued Dependencies Fourth Normal Form Reasoning About FD’s + MVD’s.
Design Theory for RDB Normal Forms. Lu Chaojun, SJTU 2 Redundant because these info may be figured out by using FD s1  … What’s Bad Design? Redundancy.
3 Spring Chapter Normalization of Database Tables.
1 Design Theory for Relational Databases Functional Dependencies Decompositions Normal Forms.
Ch 7: Normalization-Part 1
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
CS411 Database Systems Kazuhiro Minami 04: Relational Schema Design.
© D. Wong Functional Dependencies (FD)  Given: relation schema R(A1, …, An), and X and Y be subsets of (A1, … An). FD : X  Y means X functionally.
Chapter 8 Relational Database Design. 2 Relational Database Design: Goals n Reduce data redundancy (undesirable replication of data values) n Minimize.
Normalization and FUNctional Dependencies. Redundancy: root of several problems with relational schemas: –redundant storage, insert/delete/update anomalies.
Design Theory for Relational Databases Functional Dependencies Decompositions Normal Forms: BCNF, Third Normal Form Introduction to Multivalued Dependencies.
1 Lecture 8 Design Theory for Relational Databases (part 2) Slides from
1 Design Theory for Relational Databases Functional Dependencies Decompositions Normal Forms.
1 Database Design: DBS CB, 2 nd Edition Physical RDBMS Model: Schema Design and Normalization Ch. 3.
Design Theory for Relational Databases
CS422 Principles of Database Systems Normalization
Schedule Today: Next After that Normal Forms. Section 3.6.
CS422 Principles of Database Systems Normalization
CPSC-310 Database Systems
Schedule Today: Jan. 23 (wed) Week of Jan 28
3.1 Functional Dependencies
BCNF and Normalization
CPSC-310 Database Systems
Multivalued Dependencies & Fourth Normal Form (4NF)
Anomalies Boyce-Codd Normal Form 3rd Normal Form
Presentation transcript:

1 Normalization Anomalies Boyce-Codd Normal Form 3 rd Normal Form Source: Slides by Jeffrey Ullman

2 Anomalies uGoal of relational schema design is to avoid anomalies and redundancy. wUpdate anomaly : one occurrence of a fact is changed, but not all occurrences. wDeletion anomaly : a valid fact is lost when a tuple is deleted.

3 Example of Bad Design Consumers(name, addr, candiesLiked, manf, favCandy) nameaddrcandiesLikedmanf favCandy JanewayVoyagerTwizzlersHershey Smarties Janeway???SmartiesPete’s ??? SpockEnterpriseTwizzlers??? Twizzlers Data is redundant, because each of the ???’s can be figured out by using the FD’s name -> addr favCandy and candiesLiked -> manf.

4 This Bad Design Also Exhibits Anomalies nameaddrcandiesLikedmanf favCandy JanewayVoyagerTwizzlersHershey Smarties JanewayVoyagerSmartiesNestle Smarties SpockEnterpriseTwizzlersHershey 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.

5 Boyce-Codd Normal Form uWe say a relation R is in BCNF if whenever X ->A is a nontrivial FD that holds in R, X is a superkey. wRemember: nontrivial means A is not a member of set X. wRemember, a superkey is any superset of a key (not necessarily a proper superset).

6 Example Consumers(name, addr, candiesLiked, manf, favCandy) FD’s: name->addr favCandy, candiesLiked->manf uOnly key is {name, candiesLiked}. uIn each FD, the left side is not a superkey. uAny one of these FD’s shows, Consumers is not in BCNF

7 Another Example Candies(name, manf, manfAddr) FD’s: name->manf, manf->manfAddr uOnly key is {name}. uname->manf does not violate BCNF, but manf->manfAddr does.

8 Decomposition into BCNF uGiven: relation R with set of FD’s F. uCompute keys for R (sets of attributes that functionally determine all other attributes) uLook among the given FD’s for a BCNF violation X ->B. wIf any FD following from F violates BCNF, then there will surely be an FD in F itself that violates BCNF. uCompute X +. wWon't be all attributes, or else X would be a superkey and X ->B would not be a violation

9 Decompose R Using X -> B uReplace R by relations R 1 and R 2 with schemas: wR 1 : X + (all attributes "reachable" from X) wR 2 : R – (X + – X ) (X plus all attributes not "reachable" from X) uProject given FD’s F onto the two new relations (ignore FD's containing attributes no longer in the new relation). uCheck if procedure must be repeated with R 1 and/or R 2.

10 Decomposition Picture R-X +R-X + XX +-XX +-X R2R2 R1R1 R

11 Example Consumers(name, addr, candiesLiked, manf, favCandy) F = name->addr, name -> favCandy, candiesLiked->manf uPick BCNF violation name->addr. uClose the left side: {name} + = {name, addr, favCandy}. uDecomposed relations: wConsumers1(name, addr, favCandy) wConsumers2(name, candiesLiked, manf)

12 Example, Continued uWe are not done; we need to check Consumers1 and Consumers2 for BCNF. uProjecting FD’s is easy here. uFor Consumers1(name, addr, favCandy), relevant FD’s are name->addr and name->favCandy. wThus, {name} is the only key and Consumers1 is in BCNF.

13 Example, Continued uFor Consumers2(name, candiesLiked, manf), the only FD is candiesLiked -> manf, and the only key is {name, candiesLiked}. wViolation of BCNF. ucandiesLiked + = {candiesLiked, manf}, so we decompose Consumers2 into: wConsumers3(candiesLiked, manf) wConsumers4(name, candiesLiked)

14 Example, Concluded uThe resulting decomposition of Consumers : Consumers1(name, addr, favCandy) Consumers3(candiesLiked, manf) Consumers4(name, candiesLiked) uNotice: Consumers1 tells us about consumers, Consumers3 tells us about candies, and Consumers4 tells us the relationship between consumers and the candies they like.

15 Third Normal Form - Motivation uThere is one structure of FD’s that causes trouble when we decompose. uAB ->C and C ->B. wExample: A = street address, B = city, C = zip code. uThere are two keys, {A,B } and {A,C }. wThink about why. uC ->B is a BCNF violation (why?), so we must decompose into AC, BC.

16 We Cannot Enforce FD’s uThe 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. uExample with A = street, B = city, and C = zip on the next slide.

17 An Unenforceable FD uSuppose we have relation Addr with FD's: wstreet city -> zip wzip -> city uKeys are {street, city} and {street, zip} uAfter decomposing, we have relations wAddr1(street,zip) with no FD (!) wAddr2(city,zip) with FD zip -> city uConsider instances on next slide…

18 An Unenforceable FD (cont'd) street zip 545 Tech Sq Tech Sq city zip Cambridge02138 Cambridge02139 Join tuples with equal zip codes. street city zip 545 Tech Sq.Cambridge Tech Sq.Cambridge02139 Although no FD’s were violated in the decomposed relations, FD street city -> zip is violated by the database as a whole. Addr1:Addr2:

19 3NF Lets Us Avoid This Problem u3 rd Normal Form (3NF) modifies the BCNF condition so we do not have to decompose in this problem situation. uAn attribute is prime if it is a member of any key. uX ->A violates 3NF if and only if X is not a superkey, and also A is not prime.

20 Example uIn our problem situation with FD’s AB ->C and C ->B, we have keys AB and AC. uThus A, B, and C are each prime. uAlthough C ->B violates BCNF, it does not violate 3NF. uSo no need to decompose.

21 What 3NF and BCNF Give You uThere are two important properties of a decomposition: 1.Recovery : it should be possible to project the original relations onto the decomposed schema, and then reconstruct the original. 2.Dependency Preservation : it should be possible to check in the projected relations whether all the (original) given FD’s are satisfied.

22 3NF and BCNF, Continued uWe can get (1) with a BCNF decomposition. wExplanation needs to wait for relational algebra. uWe can get both (1) and (2) with a 3NF decomposition. uBut we can’t always get (1) and (2) with a BCNF decomposition. wstreet-city-zip is an example.