Functional Dependencies. FarkasCSCE 5202 Reading and Exercises Database Systems- The Complete Book: Chapter 3.1, 3.2, 3.3., 3.4 Following lecture slides.

Slides:



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

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Relational Database Design Algorithms and Further Dependencies.
Manipulating Functional Dependencies Zaki Malik September 30, 2008.
Chapter 11 Functional Dependencies. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.11-2 Topics in this Chapter Basic Definitions Trivial.
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 COP4540, SCS, FIU Functional Dependencies (Chapter 14)
Database Management Systems Chapter 3 The Relational Data Model (II) Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
Functional Dependencies - Example
Murali Mani Normalization. Murali Mani What and Why Normalization? To remove potential redundancy in design Redundancy causes several anomalies: insert,
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.
1 The Relational Data Model Functional Dependencies.
Functional Dependencies Definition: If two tuples agree on the attributes A, A, … A 12n then they must also agree on the attributes B, B, … B 12m Formally:
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.
Cs3431 Normalization. cs3431 Why Normalization? To remove potential redundancy in design Redundancy causes several anomalies: insert, delete and update.
1 Functional Dependency and Normalization Informal design guidelines for relation schemas. Functional dependencies. Normal forms. Normalization.
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.
Functional Dependencies and Relational Schema Design.
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.
Chapter 10 Functional Dependencies and Normalization for Relational Databases.
CS 405G: Introduction to Database Systems 16. Functional Dependency.
Normal Forms1. 2 The Problems of Redundancy Redundancy is at the root of several problems associated with relational schemas: Wastes storage Causes problems.
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.
Lecture 09: Functional Dependencies. Outline Functional dependencies (3.4) Rules about FDs (3.5) Design of a Relational schema (3.6)
Design Theory for Relational Databases 2015, Fall Pusan National University Ki-Joune Li.
Computing & Information Sciences Kansas State University Tuesday, 27 Feb 2007CIS 560: Database System Concepts Lecture 18 of 42 Tuesday, 27 February 2007.
Logical Database Design (1 of 3) John Ortiz Lecture 6Logical Database Design (1)2 Introduction  The logical design is a process of refining DB schema.
1 Lecture 6: Schema refinement: Functional dependencies
IST 210 Normalization 2 Todd Bacastow IST 210. Normalization Methods Inspection Closure Functional dependencies are key.
Functional Dependencies. Outline Functional dependencies (3.4) Rules about FDs (3.5) Design of a Relational schema (3.6)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
© D. Wong Ch. 3 (continued)  Database design problems  Functional Dependency  Keys of relations  Decompositions based on Functional Dependency.
1 Functional Dependencies. 2 Motivation v E/R  Relational translation problems : –Often discover more “detailed” constraints after translation (upcoming.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
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.
CS542 1 Schema Refinement Chapter 19 (part 1) Functional Dependencies.
CS411 Database Systems Kazuhiro Minami 04: Relational Schema Design.
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.
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.
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
Formal definition of a key A key is a set of attributes A 1,..., A n such that for any other attribute B: A 1,..., A n  B A minimal key is a set of attributes.
Lecture 11: Functional Dependencies
Design Theory for Relational Databases
CS422 Principles of Database Systems Normalization
CS422 Principles of Database Systems Normalization
3.1 Functional Dependencies
Functional Dependencies and Normalization
Functional Dependencies and Relational Schema Design
Lecture 09: Functional Dependencies, Database Design
Functional Dependencies
Normalization cs3431.
Instructor: Mohamed Eltabakh
Chapter 19 (part 1) Functional Dependencies
Functional Dependencies
Relational Database Design
Lecture 6: Functional Dependencies
Lecture 09: Functional Dependencies
Presentation transcript:

Functional Dependencies

FarkasCSCE 5202 Reading and Exercises Database Systems- The Complete Book: Chapter 3.1, 3.2, 3.3., 3.4 Following lecture slides are modified from Jeff Ullman’s slides for Fall Stanford

FarkasCSCE 5203 Database Design  Goal: Represent domain information Avoid anomalies Avoid redundancy  Anomalies: Update: not all occurrences of a fact are changed Deletion: valid fact is lost when tuple is deleted

FarkasCSCE 5204 Functional Dependencies  FD: X  A for relation R X functional determines A, i.e., if any two tuples in R agree on attributes X, they must also agree on attribute A. X: set of attributes A: single attribute  If t 1 and t 2 are two tuples of r over R and t 1 [X]= t 2 [X] then t 1 [A]= t 2 [A] What is the relation between functional dependencies and primary keys?

FarkasCSCE 5205 Functional Dependency Example  Owner(Name, Phone) FD: Name  Phone  Dog(Name, Breed, Age, Weight) FD: Name, Breed  Age FD: Name, Breed  Weight

FarkasCSCE 5206 Example - FD NameBreedAgeWeightDateKennel PepperG.S.17001/01/02White Oak BuddyMix45003/04/01Little Creek PepperG.S.17004/17/02Little Creek PankaVizsla124002/14/02White Oak Functional Dependencies:Name,Breed  Age Name,Breed  Weight Dog-Kennels(Name,Breed,Age,Weight,Date,Kennel)

FarkasCSCE 5207 FD with Multiple Attributes  Right side: can be more than 1 attribute – splitting/combining rule E.g., FD: Name, Breed  Age FD: Name, Breed  Weight combine into: FD: Name, Breed  Age,Weight  Left side cannot be decomposed!

FarkasCSCE 5208 FD Equivalence Let S and T denote two sets of FDs.  S and T are equivalent if the set of relation instances satisfying S is exactly the same as the set of instances satisfying T.  A set of FDs S follows from a set of FDs T if every relation instance that satisfies all FDs in T also satisfies all FDs in S.  Two sets of FDs S and T are equivalent if S follows from T and T follows from S.

FarkasCSCE 5209 Trivial FD Given FD of the form A 1,A 2,…,A n  B 1,B 2,…,B k FD is  Trivial: if the Bs are subset of As  Nontrivial: if at least one of the Bs is not among As  Completely nontrivial: if none of the Bs is in As.

FarkasCSCE Keys and FD  K is a (primary) key for a relation R if 1.K functionally determines all attributes in R 2.1 does not hold for any proper subset of K  Superkey: 1 holds, 2 does not hold

FarkasCSCE Example  Dog-Kennels(Name,Breed,Age,Weight,Date,Kennel)  Name,Breed,Date is a key: K={Name,Breed,Date} functionally determines all other attributes The above does not hold for any proper subset of K  What are? {Name,Breed,Kennel} {Name,Breed,Date,Kennel} {Name,Breed,Age} {Name,Breed,Age,Date}

FarkasCSCE Where do Keys Come From?  Assert a key K, then only FDs are K  A for all attributes A (K is the only key from FDs)  Assert FDs and deduce the keys E/R gives FDs from entity set keys and many-one relationships

FarkasCSCE E/R and Relational Keys  E/R keys: properties of entities  Relation keys: properties of tuples  Usually: one tuple corresponds to one entity  Poor relational design: one entity becomes several tuples

FarkasCSCE Closure of Attributes  Let A 1,A 2,…,A n be a set of attributes and S a set of FDs. The closure of A 1,A 2,…,A n under S is the set of attributes B such that every relation that satisfies S also satisfies A 1,A 2,…,A n  B.  Closure of attributes A 1,A 2,…,A n is denoted as {A 1,A 2,…,A n } +

FarkasCSCE Algorithm – Attribute Closure  Let X = A 1,A 2,…,A n  Find B 1,B 2,…,B k  C such that B 1,B 2,…,B k all in X but C is not in X  Add C to X  Repeat until no more attribute can be added to X  X= {A 1,A 2,…,A n } +

FarkasCSCE Closures and Keys  {A 1,A 2,…,A n } + is a set of all attributes of a relation if and only if A 1,A 2,…,A n is a superkey for the relation.

FarkasCSCE Projecting FDs  Some FD are physical laws E.g., no two courses can meet in the same room at the same time A professor cannot be at two places at the same time.  How to determine what FDs hold on a projection of a relation?

FarkasCSCE FD on Relation  Relation schema design: which FDs hold on relation  Given: X 1  A 1, X 2  A 2, …, X n  A n whether Y  B must hold on relations satisfying X 1  A 1, X 2  A 2, …, X n  A n  Example: A  B and B  C, then A  C must also hold

FarkasCSCE Inference Test  Test whether Y  B Assume two tuples agree on attributes Y Use FDs to infer these tuples also agree on other attributes If B is one of the “other” attributes, then Y  B holds.

FarkasCSCE Armstrong Axioms  Reflexivity If {A 1,A 2,…,A m } superset of {B 1,B 2,…,B n } then A 1,A 2,…,A m  B 1,B 2,…,B n  Augmentation If A 1,A 2,…,A m  B 1,B 2,…,B n then A 1,A 2,…,A m,C 1,…,C k  B 1,B 2,…,B n,C 1,…,C k  Transitivity If A 1,A 2,…,A m  B 1,B 2,…,B n and B 1,B 2,…,B n  C 1,C 2,…,C k then A 1,A 2,…,A m  C 1,C 2,…,C k

FarkasCSCE FD Closure  Compute the closure of Y, denoted as Y +  Basis: Y + = Y  Induction: look FD, where left side X is subset of Y +. If FD is X  A then add A to Y +.

FarkasCSCE Finding All FDs  Normalization: break a relation schema into two or more schemas  Example: R(A,B,C,D) FD: AB  C, C  D, D  A Decompose into (A,B,C), (A,D)  FDs of (ABC): A,B  C and C  A

FarkasCSCE Basic Idea  What FDs hold on a projections: Start with FDs Find all FDs that follow from given ones  Restrict to FDs that involve only attributes from a schema

FarkasCSCE Algorithm  For each X compute X +  Add X  A for all A in X + - X  Drop XY  A if X  A  Use FD of projected attributes

FarkasCSCE Tricks  Do not compute closure of empty set of the set of all attributes  If X + = all attributes, do not compute closure of the superset of X

FarkasCSCE Example  ABC with A  B, B  C and projection on AC: A + = ABC, yields A  B and A  C B + = BC, yields B  C C + = C, yields nothing BC + = BC, yields nothing Resulting FDs: A  B, A  C, B  C Projection AC: A  C