Functional Dependencies- Examples

Slides:



Advertisements
Similar presentations
Schema Refinement: Normal Forms
Advertisements

Schema Refinement: Canonical/minimal Covers
Non Trivial FD. Candidate Key FD’s that Hold on S.
Functional Dependencies (FDs)
Functional Dependencies- Examples
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Relational Database Design Algorithms and Further Dependencies.
Logical Database Design (3 of 3) John Ortiz. Lecture 7Logical Database Design (2)2 Normalization  If a relation is not in BCNF or 3NF, we refine it by.
Manipulating Functional Dependencies Zaki Malik September 30, 2008.
1 Design Theory. 2 Minimal Sets of Dependancies A set of dependencies is minimal if: 1.Every right side is a single attribute 2.For no X  A in F and.
Temple University – CIS Dept. CIS616– Principles of Data Management V. Megalooikonomou Functional Dependencies (based on notes by Silberchatz,Korth, and.
Properties of Armstrong’s Axioms Soundness All dependencies generated by the Axioms are correct Completeness Repeatedly applying these rules can generate.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Lecture #16: Schema Refinement & Normalization - Functional Dependencies.
Topics to be discusses Functional Dependency Key
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.
7.1 Chapter 7: Relational Database Design. 7.2 Chapter 7: Relational Database Design Features of Good Relational Design Atomic Domains and First Normal.
CS Algorithm : Decomposition into 3NF  Obviously, the algorithm for lossless join decomp into BCNF can be used to obtain a lossless join decomp.
Classroom Exercise: Normalization
Normalization DB Tuning CS186 Final Review Session.
Relational Design. DatabaseDesign Process Conceptual Modeling -- ER diagrams ER schema transformed to relational schema Designer may add additional integrity.
Normalization DB Tuning CS186 Final Review Session.
Multivalued Dependency Prepared by Tomasz Kaciak CS157A.
FDImplication: 1 Functional Dependencies (FDs) Let r(R) be a relation and let t  r, then the restriction of t to X  R, written t[X], is the projection.
Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Chapter 7: Relational Database Design First Normal.
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.
Schema Refinement and Normalization Nobody realizes that some people expend tremendous energy merely to be normal. Albert Camus.
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C3.
Cs3431 Normalization Part II. cs3431 Attribute Closure : Example Consider R (A, B, C, D, E) with FDs A  B, B  C, CD  E Does A  E hold ? (Is A  E.
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.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts Chapter 7: Relational Database Design First Normal Form Pitfalls in Relational Database Design.
Functional Dependencies Prof. Yin-Fu Huang CSIE, NYUST Chapter 11.
CS 405G: Introduction to Database Systems 16. Functional Dependency.
Computing & Information Sciences Kansas State University Monday, 13 Oct 2008CIS 560: Database System Concepts Lecture 18 of 42 Monday, 13 October 2008.
Database Systems Normal Forms. Decomposition Suppose we have a relation R[U] with a schema U={A 1,…,A n } – A decomposition of U is a set of schemas.
Multi-valued Dependencies and Fourth Normal Form
Normal Forms1. 2 The Problems of Redundancy Redundancy is at the root of several problems associated with relational schemas: Wastes storage Causes problems.
Chapter 8: Relational Database Design First Normal Form First Normal Form Functional Dependencies Functional Dependencies Decomposition Decomposition Boyce-Codd.
Schema Refinement and Normalization. Functional Dependencies (Review) A functional dependency X  Y holds over relation schema R if, for every allowable.
DAVID DENG CS157B MARCH 23, 2010 Dependency Preserving Decomposition.
Schema Refinement and Normal Forms Chapter 19 1 Database Management Systems 3ed, R.Ramakrishnan & J.Gehrke.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 7: Relational.
Functional Dependencies An example: loan-info= Observe: tuples with the same value for lno will always have the same value for amt We write: lno  amt.
THIRD NORMAL FORM (3NF) A relation R is in BCNF if whenever a FD XA holds in R, one of the following statements is true: XA is a trivial FD, or X is.
Computing & Information Sciences Kansas State University Tuesday, 27 Feb 2007CIS 560: Database System Concepts Lecture 18 of 42 Tuesday, 27 February 2007.
CS 564 Database Management Systems: Design and Implementation Discussion Session Friday, Sept 18, Apul Jain.
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 Dept. of CIS, Temple Univ. CIS616/661 – Principles of Data Management V. Megalooikonomou Integrity Constraints (based on slides by C. Faloutsos at CMU)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Minimum Cover of F. Minimal Cover for a Set of FDs Minimal cover G for a set of FDs F: –Closure of F = closure of G. –Right hand side of each FD in G.
Chapter 7 Functional Dependencies
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Lecture #16: Schema Refinement & Normalization - Functional Dependencies.
Schema Refinement and Normalization Nobody realizes that some people expend tremendous energy merely to be normal. Albert Camus.
CS 405G: Introduction to Database Systems Instructor: Jinze Liu Fall 2009.
Functional Dependencies CIS 4301 Lecture Notes Lecture 8 - 2/7/2006.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
CS 222 Database Management System Spring Lecture 4 Database Design Theory Korra Sathya Babu Department of Computer Science NIT Rourkela.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
CS542 1 Schema Refinement Chapter 19 (part 1) Functional Dependencies.
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.
Chapter 8 Relational Database Design. 2 Relational Database Design: Goals n Reduce data redundancy (undesirable replication of data values) n Minimize.
1 Lecture 9: Database Design Wednesday, January 25, 2006.
Relational Database Design (Discussion Session)
Normalization First Normal Form (1NF) Boyce-Codd Normal Form (BCNF)
How to test Whether Subschemes in BCNF??
Some slides are from Dr. Sara Cohen
CS4222 Principles of Database System
Presentation transcript:

Functional Dependencies- Examples Souhad M. Daraghma

Exercise #1: FD’s From DB Instances Below is an instance of R(A1,A2,A3,A4). Choose the FD which may hold on R A4 A1 A2A3  A4 A2A3  A1

Solution #1: FD’s From DB Instances 1. A4  A1 ??? Incorrect: The 1st and 4th tuple violates it 2. A2A3  A4 ??? Incorrect: The1st and 2nd tuple violates it. 3. A2A3  A1 ??? Correct!

Uses of Attribute Closure There are several uses of the attribute closure algorithm: Testing for superkey: To test if  is a superkey, we compute +, and check if + contains all attributes of R. Testing functional dependencies To check if a functional dependency    holds (or, in other words, is in F+), just check if   +. That is, we compute + by using attribute closure, and then check if it contains . Is a simple and cheap test, and very useful

Uses of Attribute Closure There are several uses of the attribute closure algorithm: Computing closure of F For each   R, we find the closure +, and for each S  +, we output a functional dependency   S.

Exercise #2: Checking if an FD Holds on F Using the Closure Let R(ABCDEFGH) satisfy the following functional dependencies: {A->B, CH->A, B->E, BD->C, EG->H, DE->F} Which of the following FD is also guaranteed to be satisfied by R? 1. BFG  AE 2. ACG  DH 3. CEG  AB Hint: Compute the closure of the LHS of each FD that you get as a choice. If the RHS of the candidate FD is contained in the closure, then the candidate follows from the given FDs, otherwise not.

Solution #2: Checking if an FD Holds on F Using the Closure FDs: {A->B, CH->A, B->E, BD->C, EG->H, DE->F} 1. BFG  AE ??? Incorrect: BFG+ = BFGEH, which includes E, but not A 2. ACG  DH ??? Incorrect: ACG+ = ACGBE, which includes neither D nor H. 3. CEG  AB ??? Correct: CEG+ = CEGHAB, which contains AB

Exercise #3: Checking for Keys Using the Closure Which of the following could be a key for R(A,B,C,D,E,F,G) with functional dependencies {ABC, CDE, EFG, FGE, DEC, and BCA} 1. BDF 2. ACDF 3. ABDFG 4. BDFG

Solution #3: Checking for Keys Using the Closure {AB->C, CD->E, EF->G, FG->E, DE->C, and BC->A} 1. BDF ??? No. BDF+ = BDF 2. ACDF ??? No. ACDF+ = ACDFEG (The closure does not include B) 3. ABDFG ??? No. This choice is a superkey, but it has proper subsets that are also keys (e.g. BDFG+ = BDFGECA)

Solution #3: Checking for Keys Using the Closure {AB->C, CD->E, EF->G, FG->E, DE->C, and BC->A} 4. BDFG ??? BDFG+ = ABCDEFG Check if any subset of BDFG is a key: Since B, D, F never appear on the RHS of the FDs, they must form part of the key. BDF+ = BDF  Not key So, BDFG is the minimal key, hence the candidate key

Finding Keys using FDs Tricks for finding the key: If an attribute never appears on the RHS of any FD, it must be part of the key If an attribute never appears on the LHS of any FD, but appears on the RHS of any FD, it must not be part of any key

Exercise #4: Checking for Keys Using the Closure Consider R = {A, B, C, D, E, F, G, H} with a set of FDs F = {CD→A, EC→H, GHB→AB, C→D, EG→A, H→B, BE→CD, EC→B} Find all the candidate keys of R

Solution #4: Checking for Keys Using the Closure F = {CD→A, EC→H, GHB→AB, C→D, EG→A, H→B, BE→CD, EC→B} First, we notice that: EFG never appear on RHS of any FD. So, EFG must be part of ANY key of R A never appears on LHS of any FD, but appears on RHS of some FD. So, A is not part of ANY key of R We now see if EFG is itself a key… EFG+ = EFGA ≠ R; So, EFG alone is not key

Solution #4: Checking for Keys Using the Closure Checking by adding single attribute with EFG (except A): BEFG+ = ABCDEFGH = R; it’s a key [BE→CD, EG→A, EC→H] CEFG+ = ABCDEFGH = R; it’s a key [EG→A, EC→H, H→B, BE→CD] DEFG+ = ADEFG ≠ R; it’s not a key [EG→A] EFGH+ = ABCDEFGH = R; it’s a key [EG→A, H→B, BE→CD] If we add any further attribute(s), they will form the superkey. Therefore, we can stop here searching for candidate key(s). Therefore, candidate keys are: {BEFG, CEFG, EFGH}

Exercise #5: Checking for Keys Using the Closure Consider R = {A, B, C, D, E, F, G} with a set of FDs F = {ABC→DE, AB→D, DE→ABCF, E→C} Find all the candidate keys of R

Solution #5: Checking for Keys Using the Closure F = {ABC→DE, AB→D, DE→ABCF, E→C} First, we notice that: G never appears on RHS of any FD. So, G must be part of ANY key of R. F never appears on LHS of any FD, but appears on RHS of some FD. So, F is not part of ANY key of R G+ = G ≠ R So, G alone is not a key!

Solution #5: Checking for Keys Using the Closure Now we try to find keys by adding more attributes (except F) to G Add LHS of FDs that have only one attribute (E in E→C): GE+ = GEC ≠ R Add LHS of FDs that have two attributes (AB in AB→D and DE in DE→ABCF): GAB+ = GABD GDE+ = ABCDEFG = R; [DE→ABCF] It’s a key! Add LHS of FDs that have three attributes (ABC in ABC→DE), but not taking super set of GDE: GABC+ = ABCDEFG = R; [ABC→DE, DE→ABCF] It’s a key! GABE+ = ABCDEFG = R; [AB→D, DE→ABCF] It’s a key! If we add any further attribute(s), they will form the superkey. Therefore, we can stop here. The candidate key(s) are {GDE, GABC, GABE}

Exercise #7: Calculating F+ for a Sub-Relations Consider R = {A, B, C, D, E} with a set of FDs F = {AB→DE, C→E, D→C, E→A} And we wish to project those FDs onto relation S={A, B, C} Give the FDs that hold in S Hint: We need to compute the closure of all the subsets of {A, B, C}, except the empty set and ABC. Then, we ignore the FD’s that are trivial and those that have D or E on the RHS

Solution #7: Calculating F+ for a Sub-Relations R = {A, B, C, D, E} F = {AB→DE, C→E, D→C, E→A} S={A, B, C} A+ = A B+ = B C+ = CEA [C→E, E→A] AB+ = ABDEC [AB→DE, D→C] AC+ = ACE [C→E] BC+ = BCEAD [C→E, E→A, AB→DE] We ignore D and E. So, the FDs that hold in S are: {C→A, AB→C, BC→A} (Note: BC→A can be ignored because it follows logically from C→A)

Canonical Cover Sets of functional dependencies may have redundant dependencies that can be inferred from the others Eg: A  C is redundant in: {A  B, B  C, A  C} Parts of a functional dependency may be redundant E.g. on RHS: {A  B, B  C, A  CD} can be simplified to {A  B, B  C, A  D} E.g. on LHS: {A  B, B  C, AC  D} can be simplified to {A  B, B  C, A  D} Intuitively, a canonical cover of F is a “minimal” set of functional dependencies equivalent to F, having no redundant dependencies or redundant parts of dependencies