Functional Dependencies, Normalization Rose-Hulman Institute of Technology Curt Clifton.

Slides:



Advertisements
Similar presentations
Functional Dependencies (FDs)
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Relational Database Design Algorithms and Further Dependencies.
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.
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
Murali Mani Normalization. Murali Mani What and Why Normalization? To remove potential redundancy in design Redundancy causes several anomalies: insert,
©Silberschatz, Korth and Sudarshan Relational Database Design First Normal Form Pitfalls in Relational Database Design Functional Dependencies Decomposition.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 227 Database Systems I Design Theory for Relational Databases.
1 Multivalued Dependencies Fourth Normal Form Source: Slides by Jeffrey Ullman.
1 Multivalued Dependencies Fourth Normal Form. 2 Definition of MVD uA multivalued dependency (MVD) on R, X ->->Y, says that if two tuples of R agree on.
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:
Relational Model and Relational Algebra Rose-Hulman Institute of Technology Curt Clifton.
1 CMSC424, Spring 2005 CMSC424: Database Design Lecture 9.
Winter 2002Arthur Keller – CS 1804–1 Schedule Today: Jan. 15 (T) u Normal Forms, Multivalued Dependencies. u Read Sections Assignment 1 due. Jan.
1 Normalization Anomalies Boyce-Codd Normal Form 3 rd Normal Form.
Cs3431 Normalization. cs3431 Why Normalization? To remove potential redundancy in design Redundancy causes several anomalies: insert, delete and update.
1 Normalization Anomalies Boyce-Codd Normal Form 3 rd Normal Form 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.
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.
Computing & Information Sciences Kansas State University Wednesday, 01 Oct 2008CIS 560: Database System Concepts Lecture 15 of 42 Wednesday, 01 October.
Chapter 10 Functional Dependencies and Normalization for Relational Databases.
CS 405G: Introduction to Database Systems 16. Functional Dependency.
Functional Dependencies
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.
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.
Database Normalization.
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.
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.
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.
IST 210 Normalization 2 Todd Bacastow IST 210. Normalization Methods Inspection Closure Functional dependencies are key.
© D. Wong Ch. 3 (continued)  Database design problems  Functional Dependency  Keys of relations  Decompositions based on Functional Dependency.
Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Chapter 7: Relational Database Design First Normal.
1 Functional Dependencies. 2 Motivation v E/R  Relational translation problems : –Often discover more “detailed” constraints after translation (upcoming.
Chapter 5.1 and 5.2 Brian Cobarrubia Database Management Systems II January 31, 2008.
1 Multivalued Dependencies Fourth Normal Form Reasoning About FD’s + MVD’s.
3 Spring Chapter Normalization of Database Tables.
CS 405G: Introduction to Database Systems Instructor: Jinze Liu Fall 2009.
Functional Dependencies CIS 4301 Lecture Notes Lecture 8 - 2/7/2006.
CS 338Database Design and Normal Forms9-1 Database Design and Normal Forms Lecture Topics Measuring the quality of a schema Schema design with normalization.
Ch 7: Normalization-Part 1
CS542 1 Schema Refinement Chapter 19 (part 1) Functional Dependencies.
Functional Dependencies Zaki Malik September 25, 2008.
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.
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.
Design Theory for Relational Databases Functional Dependencies Decompositions Normal Forms: BCNF, Third Normal Form Introduction to Multivalued Dependencies.
4NF & MULTIVALUED DEPENDENCY By Kristina Miguel. Review  Superkey – a set of attributes which will uniquely identify each tuple in a relation  Candidate.
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.
Design Theory for Relational Databases
Schedule Today: Next After that Normal Forms. Section 3.6.
Schedule Today: Jan. 23 (wed) Week of Jan 28
Normalization Murali Mani.
Multivalued Dependencies & Fourth Normal Form (4NF)
Functional Dependencies and Relational Schema Design
Functional Dependencies
Relational Database Design
Multivalued Dependencies
Anomalies Boyce-Codd Normal Form 3rd Normal Form
Lecture 6: Functional Dependencies
Presentation transcript:

Functional Dependencies, Normalization Rose-Hulman Institute of Technology Curt Clifton

Or…

Fixing Broken Database Designs This material will almost certainly appear on Exam II next week.

Outline  Functional Dependencies  Keys Revisited  Redundancy and Anomalies  Normalization

Functional Dependencies (FD)  Let X be a set of attributes of a relation R  Let A be a single attribute of R  X  A holds for R if: whenever two tuples of R agree on all the attributes of X, then they must also agree on the attribute A.  We say X “uniquely determines” A in R

Example  Customer(Name, Addr, SodaLiked, Manf, FavSoda), with name identifying a unique person  Lots of redundancy here… NameAddrSodaLikedManfFavSoda JanewayVoyagerPepsiPepsiCoCoke JanewayVoyagerSpriteCocaColaCoke SpockEnterprisePepsiPepsiCoCoke

FDs from Data  Does Name  Addr? NameAddrSodaLikedManfFavSoda JanewayVoyagerPepsiPepsiCoCoke JanewayVoyagerSpriteCocaColaCoke SpockEnterprisePepsiPepsiCoCoke

FDs from Data  Does Name  Addr?  Yes, since we assumed unique names NameAddrSodaLikedManfFavSoda JanewayVoyagerPepsiPepsiCoCoke JanewayVoyagerSpriteCocaColaCoke SpockEnterprisePepsiPepsiCoCoke

FDs from Data  Does Name  FavSoda? NameAddrSodaLikedManfFavSoda JanewayVoyagerPepsiPepsiCoCoke JanewayVoyagerSpriteCocaColaCoke SpockEnterprisePepsiPepsiCoCoke

FDs from Data  Does Name  FavSoda?  Yes, we want just one favorite per person NameAddrSodaLikedManfFavSoda JanewayVoyagerPepsiPepsiCoCoke JanewayVoyagerSpriteCocaColaCoke SpockEnterprisePepsiPepsiCoCoke

FDs from Data  Does SodaLiked  Manf? NameAddrSodaLikedManfFavSoda JanewayVoyagerPepsiPepsiCoCoke JanewayVoyagerSpriteCocaColaCoke SpockEnterprisePepsiPepsiCoCoke

FDs from Data  Does SodaLiked  Manf?  Yes, since each soda has just one manf. NameAddrSodaLikedManfFavSoda JanewayVoyagerPepsiPepsiCoCoke JanewayVoyagerSpriteCocaColaCoke SpockEnterprisePepsiPepsiCoCoke

FDs from Data  Does FavSoda  Name? NameAddrSodaLikedManfFavSoda JanewayVoyagerPepsiPepsiCoCoke JanewayVoyagerSpriteCocaColaCoke SpockEnterprisePepsiPepsiCoCoke

FDs from Data  Does FavSoda  Name?  No, two people might have the same favorite NameAddrSodaLikedManfFavSoda JanewayVoyagerPepsiPepsiCoCoke JanewayVoyagerSpriteCocaColaCoke SpockEnterprisePepsiPepsiCoCoke

FDs from ER Diagrams  From entity sets (Key of entity set)  other attributes of entity set  From many-one relationship (Key of “many” set)  attributes of “one” set

Drawing FDs  Use arrows to indicate FDs on schemas: Customer(Name, Addr, SodaLiked, Manf, FavSoda)

Notation Shorthand  Technically FDs go from sets to single attributes { Name }  Addr { Name }  FavSoda  Often just combine to write: Name  Addr, FavSoda  Usually omit set braces on left side also: Restaurant, Soda  Price

Keys Revisited  Let K be a set of attributes of a relation R  K is a super key for R if: For all attributes A in R, K  A  K is a key for R if: No proper subset of K is a super key for R  An attribute B is a prime attribute of R if: B is an element of some key of R

Example  What is the key here?  What are the prime attributes? Customer(Name, Addr, SodaLiked, Manf, FavSoda)

Two Ways to Find Keys  Guess a superkey K: Show that K  A for all attributes A Show that no subset of K is a superkey  Find all functional dependencies Check all possible keys

Why Talk About FDs?  Let us formally identify redundancy  Tell us how to fix it!

Redundancy Leads to Anomalies  Update anomaly: one occurrence of a fact is changed, but not all occurrences  Deletion anomaly: valid fact is lost when a tuple is deleted

Example NameAddrSodaLikedManfFavSoda JanewayVoyagerPepsiPepsiCoCoke JanewayVoyagerSpriteCocaColaCoke SpockEnterprisePepsiPepsiCoCoke Redundant with first row since Name  Addr, FavSoda Redundant with first row since SodaLiked  Manf

Normalization  Using functional dependencies to eliminate redundancy  An extremely powerful technique

Third Normal Form  A relation R is in Third Normal Form (3NF) if whenever X  A is a nontrivial functional dependency that holds in R, then either: X is a superkey for R, or A is a prime attribute of R

Normalization Algorithm  To normalize a relation R: Find the functional dependencies for R Check that whether each FD satisfies 3NF  If so, we’re done and R is normalized Otherwise let X  A be an FD that violates 3NF  Find the closure of X in R, denoted X +  Split R into new relations (R - X + + X) and X + Repeat algorithm for each new relation

Example: Grades Relation  Grade(Term, Yr, C#, Sec#, IName, SName, SAddr, S#, SSSN, Gr)

Step 1: Find the FDs

Step 2: Check for 3NF Violations  A relation R is in Third Normal Form (3NF) if whenever X  A is a nontrivial functional dependency that holds in R, then either: X is a superkey for R, or A is a prime attribute of R

Step 3: Pick a Violating FD, Find Closure  For X  A the closure of X, denoted X +, is: The set of all attributes that can be reached from any subset of X by following any FDs  Or, just follow the arrows

Step 4: Split R into Two Relations R-X +R-X + XX +-XX +-X R2R2 R1R1 R

Repeat for the New Relations  Find FDs  Check for 3NF violations  …