Functional dependencies CMSC 461 Michael Wilson. Designing tables  Now we have all the tools to build our databases  How should we actually go about.

Slides:



Advertisements
Similar presentations
Schema Refinement: Canonical/minimal Covers
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Relational Database Design Algorithms and Further Dependencies.
CS 440 Database Management Systems Practice problems for normalization.
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.
Spring 2011 Instructor: Hassan Khosravi
Normalization CMSC 461 Michael Wilson. Anomalies  Poor relational database design can lead to the occurrence of anomalies  Anomalies that we tend to.
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.
Database Management COP4540, SCS, FIU Functional Dependencies (Chapter 14)
Functional Dependencies - Example
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.
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.
Classroom Exercise: Normalization
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.
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.
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 Introduction to Database Systems CSE 444 Lectures 8 & 9 Database Design April 16 & 18, 2008.
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.
Give qualifications of instructors: DAP
Schema Refinement and Normalization Nobody realizes that some people expend tremendous energy merely to be normal. Albert Camus.
Boyce-Codd NF & Lossless Decomposition Professor Sin-Min Lee.
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 CS 186, Spring 2006, Lecture 21 R&G Chapter 19 Science is the knowledge of consequences, and dependence of one fact upon another.
Chapter 8: Relational Database Design First Normal Form First Normal Form Functional Dependencies Functional Dependencies Decomposition Decomposition Boyce-Codd.
Functional Dependencies Prof. Yin-Fu Huang CSIE, NYUST Chapter 11.
Introduction to Normalization CPSC 356 Database Ellen Walker Hiram College.
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
Design Theory for Relational Databases 2015, Fall Pusan National University Ki-Joune Li.
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.
Normal Forms through BCNF CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
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.
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,
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
1 Section 1.6 Sets. 2 Set Fundamental discrete structure on which all other discrete structures are built Can be loosely defined as a collection of elements.
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.
Functional Dependencies R&G Chapter 19 Science is the knowledge of consequences, and dependence of one fact upon another. Thomas Hobbes ( )
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
1 Multivalued Dependencies Fourth Normal Form Reasoning About FD’s + MVD’s.
3 Spring Chapter Normalization of Database Tables.
BOOLEAN ALGEBRA Only involves in calculations of TRUE and FALSE; either be inputs or output. When a logic statement is TRUE it is assigned a Boolean logic.
Schema Refinement and Normalization Nobody realizes that some people expend tremendous energy merely to be normal. Albert Camus.
Functional Dependencies CIS 4301 Lecture Notes Lecture 8 - 2/7/2006.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
MIS 3053 Database Design And Applications The University Of Tulsa Professor: Akhilesh Bajaj Normal Forms Lecture 1 © Akhilesh Bajaj, 2000, 2002, 2003.
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 Lecture 08: E/R Diagrams and Functional Dependencies Friday, January 21, 2005.
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.
Normalization and FUNctional Dependencies. Redundancy: root of several problems with relational schemas: –redundant storage, insert/delete/update anomalies.
Algebra The greatest mathematical tool of all!!. This is a course in basic introductory algebra. Essential Prerequisites: Ability to work with directed.
Case tool Relational Database Schema Designer Cai Xinlei Tang Ning Xu Chen Zhang Yichuan CS4221 P06.
Lecture 3 Algebraic Simplification
3.1 Functional Dependencies
Association Rule Mining
Design and Analysis of Multi-Factored Experiments
Functional Dependencies
Lecture 07: E/R Diagrams and Functional Dependencies
Functional Dependencies
Lecture 08: E/R Diagrams and Functional Dependencies
Chapter 3: Design theory for relational Databases
Design Theory for Relational Databases
Presentation transcript:

Functional dependencies CMSC 461 Michael Wilson

Designing tables  Now we have all the tools to build our databases  How should we actually go about doing this?  First thing’s first

Functional dependencies  Going back to relational algebra and the relational model  Identifying functional dependencies in relations help us to identify keys in a relation

What is a functional dependency (FD)?  Take a relation R  A set of attributes X = A 1,A 2,…A n in R  A set of attributes Y = B 1,B 2,…B m in R  X functionally determines Y if there’s only one X value per Y value  Every unique tuple in π A1,A2,…An maps to exactly one unique tuple in π B1,B2,…,Bm  Can also say that if a tuple has the values (a 1,a 2,…a n ), it will also have the values (b 1,b 2,…b m )  Relation R then satisfies the functional dependency X→Y

What is a functional dependency (FD)?  Tuples that have equal values for attributes in X will have equal values for attributes in Y  Let’s look at some examples

Functional dependencies  Tuples with the same values in (A 1,A 2,…A n ) will always be paired with the same values in (B 1,B 2,…B m )

Functional dependency examples titleyearlengthgenrestudioStar Star Wars SciFiFoxCarrie Fisher Star Wars SciFiFoxMark Hamill Star Wars SciFiFoxHarrison Ford Gone With the Wind DramaMGMVivien Leigh Wayne’s World ComedyParamountDana Carvey Wayne’s World ComedyParamountMike Myers

Functional dependency examples  title year → length genre studio  Does this work?  Why does it work?  Yes, this functional dependency holds  Assumption that a movie with the same title will not come out within the same year  Every unique movie will have the same length, genre, and studio name

More examples  studio → title  studio genre → title  studio genre → title year  title → year  title year → studio  title year → genre  title year → star

Functional dependency reasoning  Certain rules hold for functional dependencies that help us to reason about them  You’ve seen these rules in math classes and logic courses

Transitivity  Functional dependencies  A → B  B → C  It can be shown that, because of these two dependencies, A → C

Splitting/combining  A functional dependency  A 1,A 2,…A n → B 1,B 2,…B m  This can be split into  A 1,A 2,…A n → B 1  A 1,A 2,…A n → B 2  A 1,A 2,…A n → B m  Similarly, we can combine the aforementioned dependencies back into the original dependency

Trivial dependencies  Trivial dependencies are functional dependencies where the right side is a subset of the left  Taking A 1,A 2,…A n → B 1,B 2,…B m  If B 1,B 2,…B m is some subset of A 1,A 2,…A n  These dependencies always hold  Therefore, they are called trivial

Trivial dependencies  Intermediate situation:  A 1,A 2,…A n → B 1,B 2,…B m  Only some of the elements of B 1,B 2,…B m are in A 1,A 2,…A n  Can simply remove the elements of B 1,B 2,…B m that are in A 1,A 2,…A n to get a nontrivial dependency

Closures  Closures are a way of determining possible functional dependencies given a starting set of attributes and a few functional dependencies  You can use these to verify proposed functional dependencies  Notation for the closure of attributes A and B:  {A, B} +

Closures  In other words:  Say I have a relation R with attributes A, B, C, D, E, F,  AB → C  BC → AD  D → E  I want to know if AB → D will hold  In order to do this, I need to calculate {A, B} +

Calculating closures  In order to calculate a closure, you need a set of attributes to calculate a closure on and a set of functional dependencies to test for  If we have no existing functional dependencies, we can’t calculate closures  In calculating a closure, we’re essentially trying to see what attributes we can “jump” to given a starting set and some other dependencies  If we have no dependencies, there’s nowhere to go

Calculating closures  Input: a set of attributes {A 1,A 2,…A n }, a set S of functional dependencies  For this example  Attributes  A, B  S  AB → C  BC → AD  D → E  CF → B

Calculating closures: Step 1  Step 1: Split dependencies in S  We want to reduce all of the dependencies in S such that they are as simple as possible  Single attributes on the right side of the dependency  Why?  Makes things way easier, as we’ll see

Calculating closures: step 1  AB → C  BC → AD  D → E  CF → B

Calculating closures: step 1  AB → C  BC → A  BC → D  D → E  CF → B

Calculating closures: step 2  Step 2: Let X be your input attributes  X = {A, B}  X will eventually be your closure

Calculating closures: step 3  Step 3: Go through the functional dependencies in S. If the left side of a dependency can is satisfied by some subset of the current set of X, and the right side is not currently in X, add the right side to X  Repeat until there’s nothing left to add

Calculating closures: step 3 IIteration 1 XX = {A, B} PPossible subsets: A, B, AB SS AAB → C BBC → A BBC → D DD → E CCF → B

IIteration 2 XX = {A, B, C} PPossible subsets: A, B, C, AB, AC, BC, ABC SS AAB → C BBC → A BBC → D DD → E CCF → B

IIteration 3 XX = {A, B, C, D} PPossible subsets AA, B, C, D, AB, AC, AD, BC, BD, CD, ABC, ABD, ACD, BCD, ABCD SS DD → E CCF → B

 Iteration 4  X = {A, B, C, D, E}  S  CF → B  This doesn’t match any subset of X  Done!

Calculating closures: step 4  Step 4: Enjoy your closure  {A, B} + = {A, B, C, D, E}  F was not a part of the closure because at no point during the algorithm was there anything that “lead” to F  How could we modify S to include F?

Using closures to determine superkeys  Calculating a closure of a set of attributes  If the closure includes all attributes in the relation, then it is a superkey of the relation  Not necessarily a candidate key