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

Slides:



Advertisements
Similar presentations
Chapter 1 The Study of Body Function Image PowerPoint
Advertisements

Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
1 Term 2, 2004, Lecture 2, Normalisation - IntroductionMarian Ursu, Department of Computing, Goldsmiths College Normalisation Introduction.
CS 319: Theory of Databases
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C3.
Dr. A.I. Cristea CS 319: Theory of Databases: FDs.
ABC Technology Project
1 Undirected Breadth First Search F A BCG DE H 2 F A BCG DE H Queue: A get Undiscovered Fringe Finished Active 0 distance from A visit(A)
VOORBLAD.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
© 2012 National Heart Foundation of Australia. Slide 2.
Functional Dependencies and Normalization for Relational Databases
25 seconds left…...
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
PSSA Preparation.
4NF and 5NF Prof. Sin-Min Lee Department of Computer Science.
1 Design Theory for Relational Databases Functional Dependencies Decompositions Normal Forms.
Database Management Systems Chapter 3 The Relational Data Model (II) Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
Topics to be discusses Functional Dependency Key
Functional Dependencies, Normalization Rose-Hulman Institute of Technology Curt Clifton.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 227 Database Systems I Design Theory for Relational Databases.
Functional Dependencies
Functional Dependencies. Babies At a birth, there is one baby (twins would be represented by two births), one mother, any number of nurses, and a doctor.
1 The Relational Data Model Functional Dependencies.
1 Normalization Anomalies Boyce-Codd Normal Form 3 rd Normal Form Source: Slides by Jeffrey Ullman.
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.
1 Normalization Anomalies Boyce-Codd Normal Form 3 rd Normal Form Source: Slides by Jeffrey Ullman.
1 Functional Dependencies Why FD's Meaning of FD’s Keys and Superkeys Inferring FD’s Source: slides by Jeffrey Ullman.
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 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.
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.
Functional Dependencies. FarkasCSCE 5202 Reading and Exercises Database Systems- The Complete Book: Chapter 3.1, 3.2, 3.3., 3.4 Following lecture slides.
1 IT 244 Database Management System Topic 7 The Relational Data Model Functional Dependencies Ref : -A First Course in Database System (Jeffrey D Ullman,
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.
1 Multivalued Dependencies Fourth Normal Form Reasoning About FD’s + MVD’s.
Functional Dependencies CIS 4301 Lecture Notes Lecture 8 - 2/7/2006.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
1 Functional Dependencies 函数依赖 Meaning of FD’s Keys and Superkeys Functional Dependencies.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations Functional Dependencies.
1 Design Theory for Relational Databases Functional Dependencies Decompositions Normal Forms.
Functional Dependencies Zaki Malik September 25, 2008.
Functional Dependencies. Babies Exercise 2.2.5: At a birth, there is one baby (twins would be represented by two births), one mother, any number of nurses,
Databases 1 Sixth lecture. 2 Functional Dependencies X -> A is an assertion about a relation R that whenever two tuples of R agree on all the attributes.
Computational Biology Dr. Jens Allmer Lecture Slides Week 5.
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 Database Design: DBS CB, 2 nd Edition Physical RDBMS Model: Schema Design and Normalization Ch. 3.
Design Theory for Relational Databases
Schedule Today: Next After that Normal Forms. Section 3.6.
Schedule Today: Jan. 23 (wed) Week of Jan 28
BCNF and Normalization
Multivalued Dependencies & Fourth Normal Form (4NF)
Functional Dependencies
Functional Dependencies
Multivalued Dependencies
Anomalies Boyce-Codd Normal Form 3rd Normal Form
Presentation transcript:

1 Lecture 7 Design Theory for Relational Databases (part 1) Slides based on CS4416 Database Systems CS5122 Development of IS 2

2 Relational Schema Design 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 : valid fact is lost when a tuple is deleted.

3 Functional Dependencies (FD's)

4 Functional Dependencies uX Y is an assertion about a relation R that whenever two tuples of R agree on all the attributes of X, then they must also agree on all attributes in set Y. wSay X Y holds in R. or X functionally determines Y in R wConvention: …, X, Y, Z represent sets of attributes; A, B, C,… represent single attributes. wConvention: no set formers in sets of attributes, just ABC, rather than {A,B,C }.

5 Splitting Right Sides of FDs uX A 1 A 2 …A n holds for R exactly when each of X A 1, X A 2,…, X A n hold for R. uExample: A BC is equivalent to A B and A C. u There is no splitting rule for left sides. uWell generally express FDs with singleton right sides.

6 Example: FD's nameaddr beersLiked manffavBeer JanewayVoyager Bud A.B.WickedAle JanewayVoyager WickedAle PetesWickedAle SpockEnterprise Bud A.B.Bud Because name addr Because name favBeer Because beersLiked manf Drinkers(name, addr, beersLiked, manf, favBeer)

7 Example: FDs (contd.) Drinkers(name, addr, beersLiked, manf, favBeer) uReasonable FDs to assert: 1.name addr favBeer wThis is the same as name addr and name favBeer. 2.beersLiked manf

8 Example of Bad Design Drinkers(name, addr, beersLiked, manf, favBeer) nameaddrbeersLikedmanffavBeer JanewayVoyagerBudA.B.WickedAle Janeway???WickedAlePetes??? SpockEnterpriseBud???Bud Data is redundant, because each of the ???s can be figured out by using the FDs name addr favBeer and beersLiked manf.

9 This Bad Design Also Exhibits Anomalies nameaddrbeersLikedmanffavBeer JanewayVoyagerBudA.B.WickedAle JanewayVoyagerWickedAlePetesWickedAle SpockEnterpriseBudA.B.Bud Update anomaly: if Janeway is transferred to Intrepid, will we remember to change each of her tuples? Deletion anomaly: If nobody likes Bud, we lose track of the fact that Anheuser-Busch manufactures Bud.

10 Keys

11 Keys of Relations uK is a superkey for relation R if K functionally determines all of R. uK is a key for R if K is a superkey, but no proper subset of K is a superkey.

12 Example: Superkey Drinkers(name, addr, beersLiked, manf,favBeer) u{name, beersLiked} is a superkey because together these attributes determine all the other attributes. wname addr favBeer wbeersLiked manf

13 Example: Key u{name, beersLiked} is a key because neither {name} nor {beersLiked} is a superkey. wname doesnt manf; wbeersLiked doesnt addr. uThere are no other keys, but lots of superkeys. wAny superset of {name, beersLiked}.

14 Where Do Keys Come From? 1.Just assert a key K (usually some sort of id). wThe only FDs are K A for all attributes A. 2.Assert FDs and deduce the keys by systematic exploration. wImportant for normalization (see next lecture).

15 Inferring FD's

16 Inferring FDs uWe are given FDs X 1 A 1, X 2 A 2,…, X n A n, and we want to know whether an FD Y B must hold in any relation that satisfies the given FDs. wExample: If A B and B C hold, surely A C holds, even if we dont say so.

17 Closure Test uAn easier way to test is to compute the closure of Y, denoted Y +, and check if B is an element of in Y +. uStep 1: Start with Y + = Y. uStep 2: Look for an FDs X A whose left side X is in the current Y +. wIf there is no such FD stop. wIf there is such an FD, A to Y + and repeat Step 2.

18 Y+Y+ new Y + XA

19 Finding All Implied FDs Simple, Exponential Algorithm 1.For each set of attributes X, compute X +. 2.Add X A for all A in X + ̶ X. 3.However, drop XY A whenever we discover X A. uBecause XY A follows from X A in any projection.

20 A Few Tricks uNo need to compute the closure of the empty set or of the set of all attributes. uIf we find X + = all attributes, so is the closure of any superset of X.

21 Example uABC with FDs A B and B C. Find all implied FDs. wA + =ABC ; yields A B, A C. We do not need to compute AB + or AC +. wB + =BC ; yields B C. wC + =C ; yields nothing. wBC + =BC ; yields nothing. uResulting FDs: A B, A C, and B C.

22 Visual Representation of FD's (optional material)

23 Visual Representation of FD's uImagine the set of all instances of a particular relation. uThat is, all finite sets of tuples that have the proper number of components. uEach instance is a point in this space.

24 Example: R(A,B,C) {(1,2,3), (3,4,5)} {} {(1,2,3), (3,4,5), (1,3,5)} {(5,1,1)} {(1,2,3), (1,2,4)}

25 An FD is a Subset of Instances uFor each FD X A there is a subset of all instances that satisfy the FD. uWe can represent an FD by a region in the space. uTrivial FD = an FD that is represented by the entire space. wExample: A A.

26 Example: A -> B for R(A,B) A B {(1,2,3), (3,4,5)} {} {(1,2,3), (3,4,5), (1,3,5)} {(5,1,1)} {(1,2,3), (1,2,4)}

27 Representing Sets of FDs uIf each FD is a set of relation instances, then a collection of FDs corresponds to the intersection of those sets. wIntersection = all instances that satisfy all of the FDs.

28 Example A B B C CD A Instances satisfying A B, B C, and CD A

29 Implication of FDs uIf an FD Y B follows from FDs X 1 A 1,…,X n A n, then the region in the space of instances for Y B must include the intersection of the regions for the FDs X i A i. wThat is, every instance satisfying all the FDs X i A i surely satisfies Y B. wBut an instance could satisfy Y B, yet not be in this intersection.

30 Example A->B B->C A->C