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.

Slides:



Advertisements
Similar presentations
Schema Refinement: Normal Forms
Advertisements

Schema Refinement: Canonical/minimal Covers
primary key constraint foreign key constraint
Schema Refinement and Normal Forms
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.
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 Systems, 3ed, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 19.
CS Schema Refinement and Normal Forms Chapter 19.
Normalization DB Tuning CS186 Final Review Session.
H.Lu/HKUST L02: Logical Database Design  Introduction  Functional Dependencies  Normal Forms  Normalization by decomposition.
Normal Form Design addendum by C. Zaniolo. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Normal Form Design Compute the canonical cover.
1 Normalization Chapter What it’s all about Given a relation, R, and a set of functional dependencies, F, on R. Assume that R is not in a desirable.
Schema Refinement and Normal Forms. The Evils of Redundancy v Redundancy is at the root of several problems associated with relational schemas: – redundant.
1 Functional Dependency and Normalization Informal design guidelines for relation schemas. Functional dependencies. Normal forms. Normalization.
Schema Refinement and Normalization Nobody realizes that some people expend tremendous energy merely to be normal. Albert Camus.
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.
1 Schema Refinement and Normal Forms Yanlei Diao UMass Amherst April 10, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
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.
©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.
CS 405G: Introduction to Database Systems 16. Functional Dependency.
Database Management Systems, R. Ramakrishnan and J. Gehrke 1 Schema Refinement and Normal Forms Chapter 19 Instructor: Mirsad Hadzikadic.
Schema Refinement and Normal Forms Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
Normal Forms1. 2 The Problems of Redundancy Redundancy is at the root of several problems associated with relational schemas: Wastes storage Causes problems.
CSCD34 - Data Management Systems - A. Vaisman1 Schema Refinement and Normal Forms.
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Normalization for Relational Databases.
Schema Refinement and Normal Forms Chapter 19 1 Database Management Systems 3ed, R.Ramakrishnan & J.Gehrke.
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.
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.
Functional Dependencies and Normalization R&G Chapter 19 Lecture 26 Science is the knowledge of consequences, and dependence of one fact upon another.
Christoph F. Eick: Functional Dependencies, BCNF, and Normalization 1 Functional Dependencies, BCNF and Normalization.
Functional Dependencies And Normalization R&G Chapter 19.
Database Systems/COMP4910/Spring02/Melikyan1 Schema Refinement and Normal Forms.
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
1 Schema Refinement and Normal Forms Week 6. 2 The Evils of Redundancy  Redundancy is at the root of several problems associated with relational schemas:
1 Functional Dependencies. 2 Motivation v E/R  Relational translation problems : –Often discover more “detailed” constraints after translation (upcoming.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 15.
Announcements Program 3 due Friday Homework 2 out today, due Mon Read: Chapter 3.
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 19.
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.
CS 405G: Introduction to Database Systems Database Normalization.
1 Schema Refinement and Normal Forms Chapter The Evils of Redundancy  Redundancy is at the root of several problems associated with relational.
Ch 7: Normalization-Part 1
CS542 1 Schema Refinement Chapter 19 (part 1) Functional Dependencies.
CS411 Database Systems Kazuhiro Minami 04: Relational Schema Design.
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 19.
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.
Chapter 14 Functional Dependencies and Normalization Informal Design Guidelines for Relational Databases –Semantics of the Relation Attributes –Redundant.
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
1 CS122A: Introduction to Data Management Lecture #13: Relational DB Design Theory (II) Instructor: Chen Li.
Functional Dependency and Normalization
Schedule Today: Next After that Normal Forms. Section 3.6.
Schema Refinement and Normal Forms
UNIT - 3 DATABASE DESIGN Functional Dependencies
Database Design Dr. M.E. Fayad, Professor
Schema Refinement and Normalization
Module 5: Overview of Normalization
Schema Refinement and Normal Forms
Normalization Part II cs3431.
Decomposition and Higher Forms of Normalization
CS 405G: Introduction to Database Systems
Schema Refinement and Normalization
Schema Refinement and Normal Forms
Database Design Dr. M.E. Fayad, Professor
Chapter 7a: Overview of Database Design -- Normalization
Presentation transcript:

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 one? Conceptual design SchemasICs

Normalization A relation is said to be in a particular normal form if it satisfies a certain set of constraints. If a relation is in a certain normal form (BCNF, 3NF etc.), we know what problems it has and what problems it does not have Each normal eliminates or minimizes certain kinds of problems Given a relation, the process of making it to be in certain normal form is called normalization Typically this is done by breaking up the relation into a set of smaller relations that possess desirable properties.

Boyce-Codd Normal Form (BCNF) 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. X is a superkey. A trivial FD X  Y where Y X key nonkey attr_1nonkey attr_nnonkey attr_2 … Example 1: − Scheme: Hourly_Emps (ssn, name, lot, rating, hrly_wages, hrs_worked) − Constraints: ssn is the primary key and Rating  hrly_wages Example 2: −Schema: R(A, B, C, D) −Constraints: A is the primary key, B is a candidate key, is R a BCNF?

A BCNF relation does not allow redundancy Every field of every tuple records a piece of information that cannot be inferred from the values in all other non-key fields BCNF is the most desirable form

If a relation is not in BCNF, can we make it BCNF? Normalization Example Relation R(SNLRWH) has FDs S  SNLRWH and R  W Second FD causes violation of BCNF –consequence: W values repeatedly associated with R values We decompose SNLRWH into SNLRH and RW

A decomposition of a relation schema R The replacement of the schema R by two or more relation schemas, each contains a subset of R and together include all attributes of R. A decomposition must ensure two properties: Lossless join Dependency preservation Normalization through Decomposition

Lossless Join Decompositions Decomposition of R into X and Y is a lossless- join decomposition w.r.t. a set of FDs F if, for every instance r that satisfies F: – (r) (r) = r It is always true that r (r) (r) – In general, the other direction does not hold! If it does, the decomposition is lossless-join. It is essential that all decompositions used to deal with redundancy be lossless!

A decomposition of D={R 1,R 2,…,R m } of Relation R has the lossless join property with respect to the set of FDs F on R if for every relation instance r(R) that satisfies F, the following holds: NATURAL_JOIN( ) =r

Lossless Join Decomposition: Property 1 Property 1: A decomposition D={R1,R2} of R has the lossless join property with respect to a set of FDs F of R if and only if either is in F + or is in F +. Case 1: Case 2: R1 A B R2 B C A foreign key R1 A B R2 B C A foreign key The common attribute must be a super key for either R1 or R2.

Lossless Join Decomposition: Property 2 If (i) a decomposition D={R 1,…,R m } of R has the lossless join property with respect to a set of FDs F on R, and (ii) a decomposition D i ={Q 1,…,Q 2 } of R i has the lossless join property with respect to the projection of F on R i. then the decomposition D’={R 1,R 2,…, R i-1,Q 1,…,Q n,R i+1,…,R m } of R has the lossless join property with respect to F. Decomposition D R R 1 R 2 R 3 … R m Decomposition D 3 R3R3 Q 1 Q 2 Q 3 … Q n Decomposition D’ R R 1 R 2 Q 1 Q 2 … Q n R 4 … R m

Lossless Join Decomposition into BCNF relations Algorithm: 1 Set D  {R} 2While there is a relation schema Q in D that is not in BCNF do begin Choose a relation schema Q in D that is not in BCNF; Find a functional dependency X  Y in Q that violates BCNF; Replace Q in D by two schemas (Q-Y) and (XUY) end; We have Since X  Y is in F, D={(Q-Y),(X Y)} has the lossless join property.

Exercise Determine whether D={R1,R2, R3} of R(S,E,P,N,L,H) is a lossless-join decomposition. R1={S,E} R2={P,N,L} R3={S,P,H} F={S  E, SP  H, P  NL}

R with a set of FDs F projection R 1 R 2 R n F R1 F R2 F Rn The projection of F on R i (F Ri ) is defined as: D={R 1,…,R n } of R is dependency preserving with respect to F if. DEPENDENCY PRESERVATION D={R 1,…,R n } is a decomposition of R., meaning that is equivalent to F.

We want to preserve the dependencies because each FD in F represents a constraint on the database. We want each original FD to be represented by some individual relation Ri so we can check the constraint without joining two or more relations. Otherwise, each update would require to do join operations Example: Contracts (C S J D P Q V) Contracts(contractid, supplierid, projectid, deptid, partid, qty, value) DEPENDENCY PRESERVATION C  CSJDPQV JP  C SD  P J  S Is it BCNF?

Example: Contracts (C S J D P Q V) SDP CSDJQV JS CJDQV SD  P JSJS DEPENDENCY PRESERVATION C  CSJDPQV JP  C SD  P J  S Loss-less join decomposition?

Example: Contracts (C S J D P Q V) SDP CSDJQV JS CJDQV SD  P JSJS Where JP  C is in the result of the decomposition? To enforce JP  C, we need to join the three relations for each update DEPENDENCY PRESERVATION C  CSJDPQV JP  C SD  P J  S

Example: Contracts (C S J D P Q V) JS CJDPQV J->S Is this decomposition lossless join and dependency preserving? An alternative decomposition C  CSJDPQV JP  C SD  P J  S

Question Can any relation be decomposed into BCNF while ensuring lossless join and dependency preservation?

In general, there may not be a dependency preserving decomposition into BCNF. – e.g., CSZ, CS  Z, Z  C – what NF? – Let’s consider a decomposition D={ZC,SZ}. – what NF? Is lossless-join decomposition? – Is CS  Z preserved? – CS + ={C,S,Z}; SZ + = {S,Z,C}; ZC + ={Z,C} – R1(ZC); F R1 ={Z  C} – R2(SZ); F R2 ={SZ  Z, SZ  S} = {Z  C,SZ  Z,SZ  S} + Is CS  Z in ?