1 Functional Dependencies 函数依赖 Meaning of FD’s Keys and Superkeys Functional Dependencies.

Slides:



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

Manipulating Functional Dependencies Zaki Malik September 30, 2008.
Spring 2011 Instructor: Hassan Khosravi
1 Design Theory for Relational Databases Functional Dependencies Decompositions Normal Forms.
Temple University – CIS Dept. CIS616– Principles of Data Management V. Megalooikonomou Functional Dependencies (based on notes by Silberchatz,Korth, and.
Database Management COP4540, SCS, FIU Functional Dependencies (Chapter 14)
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 6 A First Course in Database Systems.
Database Management Systems Chapter 3 The Relational Data Model (II) Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
Functional Dependencies - Example
Database Systems The Relational Data Model
Topics to be discusses Functional Dependency Key
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 227 Database Systems I Design Theory for Relational Databases.
Midterm Review II. Redundancy. –Information may be repeated unnecessarily in several tuples. –E.g. length and filmType. Update anomalies. –We may change.
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.
Closure The closure of {B 1 …B k } under the set of FDs S, denoted by {B 1 …B k } +, is defined as follows: {B 1 …B k } + = {B | any relation satisfies.
The Relational Data Model Database Model (E/R) Relational Schema Physical storage Diagrams (E/R) Tables: row names: attributes rows: tuples Complex file.
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.
1 CMSC424, Spring 2005 CMSC424: Database Design Lecture 9.
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.
From E/R Diagrams to Relations. The Relational Data Model Database Model (E/R) Relational Schema Physical storage Diagrams (E/R) Tables: row names: attributes.
1 Functional Dependencies Why FD's Meaning of FD’s Keys and Superkeys Inferring FD’s Source: slides by Jeffrey Ullman.
Bad DB Design Duplicate of data Duplicate of data Updating Updating Deleting Deleting.
Fall 2001Arthur Keller – CS 1804–1 Schedule Today Oct. 4 (TH) Functional Dependencies and Normalization. u Read Sections Project Part 1 due. Oct.
Chapter 8: Relational Database Design First Normal Form First Normal Form Functional Dependencies Functional Dependencies Decomposition Decomposition Boyce-Codd.
1 Design Theory for Relational Databases Functional Dependencies Decompositions Normal Forms.
Asst.Prof.Dr.İlker Kocabaş UBİ502 at
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.
Design Theory for Relational Databases 2015, Fall Pusan National University Ki-Joune Li.
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.
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 Dept. of CIS, Temple Univ. CIS616/661 – Principles of Data Management V. Megalooikonomou Integrity Constraints (based on slides by C. Faloutsos at CMU)
© D. Wong Ch. 3 (continued)  Database design problems  Functional Dependency  Keys of relations  Decompositions based on Functional Dependency.
1 Design Theory for Relational Databases Functional Dependencies Decompositions Normal Forms.
1 Multivalued Dependencies Fourth Normal Form Reasoning About FD’s + MVD’s.
1 Multivalued Dependencies Fourth Normal Form Reasoning About FD’s + MVD’s.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations.
Functional Dependencies CIS 4301 Lecture Notes Lecture 8 - 2/7/2006.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
Functional dependencies CMSC 461 Michael Wilson. Designing tables  Now we have all the tools to build our databases  How should we actually go about.
Multivalued Dependencies and 4th NF CIS 4301 Lecture Notes Lecture /21/2006.
CS 222 Database Management System Spring Lecture 4 Database Design Theory Korra Sathya Babu Department of Computer Science NIT Rourkela.
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.
CPSC 603 Database Systems Lecturer: Laurie Webster II, M.S.S.E., M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 5 Introduction to a First Course in Database Systems.
CS411 Database Systems Kazuhiro Minami 04: Relational Schema Design.
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.
© 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.
Databases : Functional Dependencies 2007, Fall Pusan National University Ki-Joune Li.
Design Theory for Relational Databases Functional Dependencies Decompositions Normal Forms: BCNF, Third Normal Form Introduction to Multivalued Dependencies.
1 Chapter 3 The Relational Data Model. 2 Contents u3.1 Basics of the Relational Model u3.2 From E/R diagrams to Relational Designs u3.4 Functional 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
Functional Dependency
Transforming E/R to Relational Model.
Design Theory for Relational Databases
Functional Dependencies
Functional Dependencies
Multivalued Dependencies
Design Theory for Relational Databases
Presentation transcript:

1 Functional Dependencies 函数依赖 Meaning of FD’s Keys and Superkeys Functional Dependencies

2 uX → A 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 the attribute A. wSay “X → A holds 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 }.

3 Example Movies(title, year,length,filmType,studioname) uReasonable FD’s to assert: 1.tile year → length 2.tile year → filmType 3.tile year → studioName titleyearlengthfilm typestudioNamestarName Star Wars Mighty Ducks Wayne’s World color Fox Disney Paramount Carrie Fisher Mark Hamill Harrison Ford Emilio Estevez Dana Carvey Mike Meyers

4 FD’s With Multiple Attributes uNo need for FD’s with > 1 attribute on right. wBut sometimes convenient to combine FD’s as a shorthand. wExample: tile year → length, tile year → filmType and tile year → studioName become tile year → length filmType studioName

5 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.

6 Example Movies(title, year,length,filmType,studioname) u {tile, year,starName} is a superkey because together these attributes determine all the other attributes. u{tile, year,starName,length,filmType} is a superkey too.

7 E/R and Relational Keys uKeys in E/R concern entities. uKeys in relations concern tuples. uUsually, one tuple corresponds to one entity, so the ideas are the same. uBut --- in poor relational designs, one entity can become several tuples, so E/R keys and Relational keys are different.

8 Example Drinkers addrname Beers manfname Bars name license addr Note: license = beer, full, none Sells Bars sell some beers. Likes Drinkers like some beers. Frequents Drinkers frequent some bars.

9 Example Data (Cont.) nameaddr beersLiked manffavBeer JanewayVoyager Bud A.B.WickedAle JanewayVoyager WickedAle Pete’sWickedAle SpockEnterprise Bud A.B.Bud Relational key = {name beersLiked} But in E/R, name is a key for Drinkers, and beersLiked is a key for Beers. Note: 2 tuples for Janeway entity and 2 tuples for Bud entity.

10 Where Do Keys Come From? 1.Just assert a key K. wThe only FD’s are K → A for all attributes A. 2.Assert FD’s and deduce the keys by systematic exploration. wE/R model gives us FD’s from entity-set keys and from many-one relationships.

11 More FD’s From “Physics” uExample: “no two courses can meet in the same room at the same time” tells us: hour room → course.

12 Rules About Functional Dependencies uThe Splitting/Combining Rule  We can replace a FD A 1 A 2 …A n → B 1 B 2 …B m by a set of FD’s A 1 A 2 …A n → B i,for i=1,2,…,m. This transformation we call splitting rules.  We can replace a set of FD’s A 1 A 2 …A n → B i for i=1,2,…,m by a set A 1 A 2 …A n → B 1 B 2 …B m,. This transformation we call combining rules.

13 Examples title year → length title year → studioName title year → length studioName

14 More Consider FD: title year → length if we try to split the left side into title → length year → length Then we get two false FD’s.

15 uA functional dependency A 1 A 2 …A n →B is said to be trivial( 平凡 ) if B is one of the A’s, otherwise is said to be nontrivial( 非平凡 ). wExample: Suppose Functional Dependencies title, year → title is a trivial dependency. Trivial Dependencies

16 The Closure of Attributes Suppose { A 1,A 2,…,A n } is a set of attributes and S is a set of FD’s. The closure of { A 1,A 2,…,A n } under the FD’s in S is the set of attributes B such that every relation that satisfies all the FD’s in the set S also satisfies A 1 A 2 …A n → B. That is, A 1 A 2 …A n → B follows from the FD’s of S.

17 Computing the c losure uAn easier way to test is to compute the closure of Y, denoted Y +. uBasis: Y + = Y. uInduction: Look for an FD’s left side X that is a subset of the current Y +. If the FD is X -> A, add A to Y +.

18 Y+Y+ new Y + XA

19 Example uR = (A, B, C, G, H, I) uF = {A  B A  C CG  H CG  I B  H} u(AG) + 1.result = AG 2.result = ABCG(A  C and A  B) 3.result = ABCGH(CG  H and CG  AGBC) 4.result = ABCGHI(CG  I and CG  AGBCH) uIs AG a candidate key? 1.Is AG a super key? 1.Does AG  R? == Is (AG) +  R 2.Is any subset of AG a superkey? 1.Does A  R? == Is (A) +  R 2.Does G  R? == Is (G) +  R

20 例 设关系模式 R ( U,F ), 其中, U={A,B,C,D,E,I},F={A → D,AB → C,BI → C,E D → I,C → E}, 求( AC ) F + 。 解: (1) 令 X={AC}, 则 X(0)=AC 。 (2) 在 F 中找出左边是 AC 子集的函数依赖: A→D,C→E 。 (3) X(1)=X(0) ∪ D ∪ E=ACDE 。 Another Examples

21 (4) 很明显 X(1)≠X(0), 所以 X(i)=X(1), 并转向算法中的步 骤 (2) 。 (5) 在 F 中找出左边是 ACDE 子集的函数依赖: ED → I 。 (6) X(2)=X(1) ∪ I=ACDEI 。 (7) 虽然 X(2)≠X(1), 但是 F 中未用过的函数依赖的左边属性 已没有 X(2) 的子集, 所以, 可停止计算, 输出( AC ) F + = X(2)=ACDEI 。

22 uTransitive( 传递 ) Functional Dependencies wSuppose we have a relation R with three attributes A, B, and C, the FD’s A→B and B→C both hold for R. Then it is easy to see that the FD A→C also holds for R, So C is said to depend on A transitively, via B. The transitive rule

23 Examples uTwo of the FD’s wtitle year → studioName wstudioName → studioAddr uCombine the two FD’s above to get wtitle year → studioAddr titleyearlengthfilm typestudioNamestudioAddr Star Wars Mighty Ducks Wayne’s World color Fox Disney Paramount Holleywood Buena Vista Holleywood

24 Closing Sets of Functional Dependencies uAny set of given FD’s from which we can infer all the FD’s for a relation will be called a basis for that relation. If no proper subset of the FD’s in the basis can also derive the complete set of FD’s, then we say the basis is minimal, that is the closing set of the functional dependencies of the relation uConsider a relation R(A,B,C), One of its FD’s is {A → B,B → A, B → C,C → B} uAnother is {A → B,B → C,C → A}