1 CS 430 Database Theory Winter 2005 Lecture 9: Fourth and Fifth Normal Forms.

Slides:



Advertisements
Similar presentations
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Relational Database Design Algorithms and Further Dependencies.
Normalization 1 Instructor: Mohamed Eltabakh Part II.
Schema Refinement and Normal Forms Given a design, how do we know it is good or not? What is the best design? Can a bad design be transformed into a good.
METU Department of Computer Eng Ceng 302 Introduction to DBMS Further Dependencies by Pinar Senkul resources: mostly froom Elmasri, Navathe and other books.
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.
Relational Normalization Theory. Limitations of E-R Designs Provides a set of guidelines, does not result in a unique database schema Does not provide.
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.
Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Chapter 7: Relational Database Design First Normal.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Basics of Functional Dependencies and Normalization for Relational.
Copyright © 2004 Pearson Education, Inc.. Chapter 11 Relational Database Design Algorithms and Further Dependencies.
 10.1 CS 728 Advanced Database Systems Chapter 11 Relational Database Design Algorithms and Further Dependencies.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. Relational Database Design - part 2 - Database Management Systems I Alex Coman,
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:
Nov 11, 2003Murali Mani Normalization B term 2004: lecture 7, 8, 9.
1 Database Design Theory Which tables to have in a database Normalization.
1 Functional Dependency and Normalization Informal design guidelines for relation schemas. Functional dependencies. Normal forms. Normalization.
1 Multi-valued Dependencies. 2 Multivalued Dependencies There are database schemas in BCNF that do not seem to be sufficiently normalized. Consider a.
MVDs: 1 Join Dependencies—Example Let r = A B C = A B |  | A C 1 a x 1 a 1 x 1 a y 1 b 1 y 1 b x 2 a 2 y 1 b y 2 b 2 a y 2 b y Observe: r =  AB r | 
Department of Computer Science and Engineering, HKUST Slide 1 7. Relational Database Design.
METU Department of Computer Eng Ceng 302 Introduction to DBMS Relational Database Design Algorithms by Pinar Senkul resources: mostly froom Elmasri, Navathe.
Chapter 11 Relational Database Design Algorithms and Further Dependencies Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
Introduction to Schema Refinement
©Silberschatz, Korth and Sudarshan7.1Database System Concepts Chapter 7: Relational Database Design First Normal Form Pitfalls in Relational Database Design.
Chapter 10 Functional Dependencies and Normalization for Relational Databases Copyright © 2004 Pearson Education, Inc.
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.
Copyright © Curt Hill Schema Refinement III 4 th NF and 5 th NF.
Relational Database Design by Relational Database Design by Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING.
Chapter 8: Relational Database Design First Normal Form First Normal Form Functional Dependencies Functional Dependencies Decomposition Decomposition Boyce-Codd.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Further Normalization II: Higher Normal Forms Prof. Yin-Fu Huang CSIE, NYUST Chapter 13.
Topic 10 Functional Dependencies and Normalization for Relational Databases Faculty of Information Science and Technology Mahanakorn University of Technology.
Instructor: Churee Techawut Functional Dependencies and Normalization for Relational Databases Chapter 4 CS (204)321 Database System I.
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.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide DESIGNING A SET OF RELATIONS (2) Goals: Lossless join property (a must). Dependency.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 4 Normalization.
BCNF & Lossless Decomposition Prof. Sin-Min Lee Department of Computer Science.
Chapter 10 Functional Dependencies and Normalization for Relational Databases Copyright © 2004 Pearson Education, Inc.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 11 Relational Database Design Algorithms and Further Dependencies.
Computing & Information Sciences Kansas State University Wednesday, 04 Oct 2006CIS 560: Database System Concepts Lecture 17 of 42 Wednesday, 04 October.
Relational Database Design Algorithms and Further Dependencies.
Chapter Functional Dependencies and Normalization for Relational Databases.
CSE314 Database Systems Basics of Functional Dependencies and Normalization for Relational Databases Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E.
Chapter 11: Relational Database Design Algorithms and Further Dependencies Chapter 11: Relational Database Design Algorithms and Further Dependencies 1.
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 Functional Dependencies and Normalization Chapter 15.
© D. Wong Ch. 3 (continued)  Database design problems  Functional Dependency  Keys of relations  Decompositions based on Functional Dependency.
Copyright, Harris Corporation & Ophir Frieder, The Process of Normalization.
Design Process - Where are we?
Normalization.
Ch 7: Normalization-Part 1
CS411 Database Systems Kazuhiro Minami 04: Relational Schema Design.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Relational Database Design Algorithms and Further Dependencies.
Chapter 8 Relational Database Design. 2 Relational Database Design: Goals n Reduce data redundancy (undesirable replication of data values) n Minimize.
1 CS 430 Database Theory Winter 2005 Lecture 8: Functional Dependencies Second, Third, and Boyce-Codd Normal Forms.
Normal Forms Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems June 18, 2016 Some slide content courtesy of Susan Davidson.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Normalization Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 19.
Chapter 15 Relational Design Algorithms and Further Dependencies
Higher Forms of Normalization
Relational Database Design by Dr. S. Sridhar, Ph. D
CS 480: Database Systems Lecture 22 March 6, 2013.
11/12/2018.
Relational Database Design Algorithms and Further Dependencies
Join Dependencies and Fifth Normal Form
Chapter 7a: Overview of Database Design -- Normalization
Presentation transcript:

1 CS 430 Database Theory Winter 2005 Lecture 9: Fourth and Fifth Normal Forms

2 Decompositions Given a relation R = {A 1, …, A n } (all of the A i are unique), then a set of relation schemas D = {R 1, …, R m } is a decomposition of R if R is the union of the R i, or That is, all the attributes of R appear in the R i

3 Goodness of Decomposition When is a decomposition “good”? Two standards:  Dependency Preservation  Lossless (Nonadditive) Join

4 Dependency Preservation Suppose we have a set of FDs F on R and a decomposition D = {R 1, …, R m }, the projection of F on R is the set  Ri (F) = { X  Y  F + | X  Y  R i } That is,  Ri (F) consists of all the FDs in the closure of F which are FDs on R i

5 Dependency Preservation D is Dependency Preserving with respect to F if the closure of the union of the projections of F onto the R i is the closure of F. Or, (  R1 (F)  …   Rm (F)) + = F + Or, if we project F onto the individual R i, union the projections together, and compute the closure, we get the original closure of F.  Or, no information contained in F is lost by projecting F onto the individual R i

6 Dependency Preservation Notes Claim: It is possible to find a 3NF decomposition of R (each of Ri is 3NF) which is dependency preserving  See Algorithm 11.2, page 340. (No proof.) Why do we want this?  When we update the database, we want to be able verify FDs by verifying them on the individual relations  The alternative is having to do joins to verify that our update is good, slowing system.

7 Lossless (Nonadditive) Join Property D has the Lossless (Nonadditive) Join property with respect to a set of FDs F if for every relation state r of R that satisfies F:  R1 (r)  …   Rm (r) = r (  is the natural join) Lossless means no loss of information Nonadditive means that natural join doesn’t add any information

8 Lossless (Nonadditive) Join Notes Algorithm 11.1, page 337, provides a way to test for this property If D is a binary decomposition, D = {R1, R2}, D is nonadditive if and only if: (R1  R2)  (R1 - R2) is in F+, or (R1  R2)  (R2 - R1) is in F+ That is, R1  R2 is a key for (at least) one of R1 or R2

9 Aside: Null Problems with Nulls See Figures 11.2, 11.3, Text Book Bottom line: If nulls are present, especially nulls in foreign keys then  May have to use outer joins instead of ordinary (inner) joins  Have to be careful if using aggregation (e.g. sum or average)

10 Multi-Value Dependencies If X, Y attributes of R there is a Multi-Valued Dependency (MVD) X  > Y, (we let Z = R - ( X  Y )) if for all states r of R, and t 1, t 2 tuples of r such that t 1 [ X ] = t 2 [ X ], then there exist tuples t 3, t 4 of r such that: t 3 [ X ] = t 4 [ X ] = t 1 [ X ] = t 2 [ X ] t 3 [ Y ] = t 1 [ Y ], t 4 [ Y ] = t 2 [ Y ] t 4 [ Z ] = t 1 [ Z ], t 3 [ Z ] = t 2 [ Z ] An MVD X  > Y, is trivial if Y  X, or X  Y = R

11 Fourth Normal Form R is 4NF with respect to a set of FDs and MVDs F if for every non-trivial MVD X  > Y, X is a superkey of R. See Figure 11.4(a, b) in Text Book.

12 Fourth Normal Form Notes If a relation is not 4NF then there are update anomalies:  If you add a relation you must also add the corresponding relations D is a lossless (nonadditive) decomposition of R, D = {R 1, R 2 }, with respect to a set of FDs and MVDs F if and only if: (R 1  R 2 )  > (R 1 - R 2 ), which is the same as (R 1  R 2 )  > (R 2 - R 1 )

13 Fifth Normal Form JD(R 1, …, R m ) is a Join Dependency (JD) for a decomposition {R 1, …, R m } of R if for every legal state r of R:  R1 (r)  …   Rm (r) = r A JD is trivial if some R i = R A relation R is in Fifth Normal Form (5NF) if for every non-trivial JD of R, every R i is a superkey of R

14 Notes on Fifth Normal Form An MVD is a JD with m = 2 Finding all the JDs of a database of any size is probably not feasible Example: See Figure 11.4 (c, d) of Text Book

15 Products, Salesmen, Territories A Data Design Problem Salesman  Sells specific products  Has specific territories  Has a quota: How much he is supposed to sell Product  Sold by salesmen  Has a price Territory  Worked by salesmen

16 ER Model Version 1 Product Salesman Territory Sells Product Works Territory Quota Price A Salesman can sell any Product he sells in any Territory he works. A Product has one Price for all Salesmen and all Territories. A Salesman has one Quota for all his sales. Note: Each Entity and Relation becomes a relation in our database.

17 ER Model Version 2 Product Salesman Territory Sells Product Works Territory Quota Price A Salesman has a Quota for each product he sells.

18 ER Model Version 3 Product Salesman Territory Sells Product Works Territory Quota Price Products are only sold in specific Territories. A Product has a Price set for each Territory where it is sold. A Salesman can sell any Product he sells in any Territory he works where that Product is sold. Note JD between “Sells Product”, “Sold In”, and “Works Territory”. Sold In

19 ER Model Version 4 Product Salesman Territory Sells Product Sells Product in Territory Quota Price A Salesman is assigned to sell specific Products in specific Territories. A Salesman has a Quota for each Product he sells in each Territory. Possible Integrity Constraint: Keys of “Sells Product” and “Sold In” are projections of “Sells Product in Territory”. Sold In

20 ER Model Version 4A Product Salesman Territory Sells Product in Territory Quota Price Possible Integrity Constraint: Key of “Sold In” is projection of “Sells Product in Territory”. (But I might want to assign a Price even though no Salemen have yet been assigned that Product in that Territory.) Sold In

21 Sample Fields Employee  Employee ID Number  Employee Name  Work Location  Manager Manager ID Number Manager Name Territory  Territory Number  Territory Name  Territory Bonus Product  Product Number  Product Name  Price  Actual_Sales  Target_Sales Other  Quota  Commission Rate  Commission  Manager Commission

22 Possible Functional Dependencies {Employee ID Number}   {Employee Name, Work Location, Manager ID Number, Manager Commission(?)} {Manage ID Number}   {Manager Name, Manager Commission(?)} {Territory Number}   {Territory Name, Territory Bonus(?)} {Product Number}   {Product Name, Price(?), Actual Sales(?), Target Sales (?)}

23 More Possible FDs {Employee ID Number, Territory Number}   {Territory Bonus(?), Quota(?), Commission Rate(?)} {Employee ID Number, Product Number}   {Quota(?), Commission Rate(?)} {Territory Number, Product Number}   {Price(?), Actual Sales(?), Target Sales(?), Territory Bonus(?), Commission Rate(?), Commission(?), Manager Commission(?)}

24 More Possible FDs {Employee ID Number, Product Number, Territory Number}   {Quota(?), Actual Sales(?), Target Sales(?), Commission Rate(?), Commission(?), Manager Commission(?)} {Actual Sales, Commission Rate}   {Commission} {Actual Sales, Manager Commission Rate}   {Manager Commission}

25 Proposed Solution Employee(Employee ID Number, Employee Name, Work Location, Manager ID Number) Manager(Manager ID Number, Manager Name, Manager Commission) Territory(Territory Number, Territory Name) Product(Product Number, Product Name)

26 More Proposed Solution Product_Territory(Product Number, Territory Number, Price) Employee_Territory(Employee ID Number, Territory Number, Territory Bonus) Employee_Product(Employee ID Number, Product Number, Commission Rate) Employee_Product_Territory(Employee ID Number, Product Number, Territory Number, Quota, Actual Sales, Target Sales, Commission, Manager Commission)