CPSC-310 Database Systems

Slides:



Advertisements
Similar presentations
Normal Form Design addendum by C. Zaniolo. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Normal Form Design Compute the canonical cover.
Advertisements

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 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.
Fall 2001Arthur Keller – CS 1804–1 Schedule Today Oct. 4 (TH) Functional Dependencies and Normalization. u Read Sections Project Part 1 due. Oct.
Chapter 14 Advanced Normalization Transparencies © Pearson Education Limited 1995, 2005.
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.
Decompositions uDo we need to decompose a relation? wSeveral normal forms for relations. If schema in these normal forms certain problems don’t.
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.
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.
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.
IST 210 Normalization 2 Todd Bacastow IST 210. Normalization Methods Inspection Closure Functional dependencies are key.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
1 Multivalued Dependencies Fourth Normal Form Reasoning About FD’s + MVD’s.
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.
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.
1 Lecture 8 Design Theory for Relational Databases (part 2) Slides from
Lecture 11: Functional Dependencies
Advanced Normalization
Design Theory for Relational Databases
CS422 Principles of Database Systems Normalization
Design Theory for RDB Normal Forms.
Schedule Today: Next After that Normal Forms. Section 3.6.
Relational Database Design (Discussion Session)
Schema Refinement and Normal Forms
CS411 Database Systems 08: Midterm Review Kazuhiro Minami 1.
Normalization First Normal Form (1NF) Boyce-Codd Normal Form (BCNF)
CS422 Principles of Database Systems Normalization
Canonical Cover & Normal Forms
CPSC-310 Database Systems
Schedule Today: Jan. 23 (wed) Week of Jan 28
CS 480: Database Systems Lecture 22 March 6, 2013.
3.1 Functional Dependencies
Handout 4 Functional Dependencies
Advanced Normalization
CPSC-310 Database Systems
Schema Refinement and Normalization
Relational Design Theory
BCNF and Normalization
Functional Dependencies and Normalization
CPSC-310 Database Systems
Schema Refinement and Normalization
Canonical Cover & Normal Forms
How to test Whether Subschemes in BCNF??
Multivalued Dependencies & Fourth Normal Form (4NF)
Cse 344 May 16th – Normalization.
Functional Dependencies and Relational Schema Design
Introduction to Database Systems CSE 444 Lectures 8 & 9 Database Design October 12 & 15, 2007.
Relational Design Theory
Normalization Part II cs3431.
Lecture 8: Database Design
Functional Dependencies
Lecture 07: E/R Diagrams and Functional Dependencies
CS 405G: Introduction to Database Systems
Boyce-Codd Normal Form
Functional Dependencies
Third Normal Form.
Multivalued Dependencies
Anomalies Boyce-Codd Normal Form 3rd Normal Form
Lecture 6: Functional Dependencies
Chapter 3: Design theory for relational Databases
Chapter 7a: Overview of Database Design -- Normalization
Lecture 09: Functional Dependencies
CS4222 Principles of Database System
Presentation transcript:

CPSC-310 Database Systems Professor Jianer Chen Room 315C HRBB Lecture #6

Computing Closure Computing the closure Y+ of a set Y of attributes. Algorithm Closure(Y) 1. Y+ = Y; 2. While changes Do 2.1 look for an FD X → B where X is a subset of Y+ but B is not in Y+; 2.2 add B to Y+; 3. every A in Y+\Y satisfies Y → A Y+ new Y+ X A It can be proved that the Algorithm Closure(Y) finds exactly those FDs Y → A implied by the given FDs.

Eliminating bad FD X → A (for all A) Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

Normalization Algorithm Algorithm Normalization(R, T) Input: A relation R with attribute set Z and FD set T.

Normalization Algorithm Algorithm Normalization(R, T) Input: A relation R with attribute set Z and FD set T. 1. For each subset Y of Z Do construct Y+;

Normalization Algorithm Algorithm Normalization(R, T) Input: A relation R with attribute set Z and FD set T. 1. For each subset Y of Z Do construct Y+; 2. Record the superkeys and keys Y for R (Y+=Z);

Normalization Algorithm Algorithm Normalization(R, T) Input: A relation R with attribute set Z and FD set T. 1. For each subset Y of Z Do construct Y+; 2. Record the superkeys and keys Y for R (Y+=Z); 3. If there is a subset Y of Z such that Y+≠ Z and Y+≠ Y \\ Y → A is a bad FD for some A

Normalization Algorithm Algorithm Normalization(R, T) Input: A relation R with attribute set Z and FD set T. 1. For each subset Y of Z Do construct Y+; 2. Record the superkeys and keys Y for R (Y+=Z); 3. If there is a subset Y of Z such that Y+≠ Z and Y+≠ Y \\ Y → A is a bad FD for some A Then 3.1 Call Decomposition(Y) to decompose the relation R into two smaller relations R1 and R2;

Normalization Algorithm Algorithm Normalization(R, T) Input: A relation R with attribute set Z and FD set T. 1. For each subset Y of Z Do construct Y+; 2. Record the superkeys and keys Y for R (Y+=Z); 3. If there is a subset Y of Z such that Y+≠ Z and Y+≠ Y \\ Y → A is a bad FD for some A Then 3.1 Call Decomposition(Y) to decompose the relation R into two smaller relations R1 and R2; 3.2 Call Decomposed-FDs(Rk) for k = 1, 2 to construct the FD sets T1 for R1 and T2 for R2;

Normalization Algorithm Algorithm Normalization(R, T) Input: A relation R with attribute set Z and FD set T. 1. For each subset Y of Z Do construct Y+; 2. Record the superkeys and keys Y for R (Y+=Z); 3. If there is a subset Y of Z such that Y+≠ Z and Y+≠ Y \\ Y → A is a bad FD for some A Then 3.1 Call Decomposition(Y) to decompose the relation R into two smaller relations R1 and R2; 3.2 Call Decomposed-FDs(Rk) for k = 1, 2 to construct the FD sets T1 for R1 and T2 for R2; Example. R(A, B, C, D, E) T = {AB → D, AC → E, BC → D, D → A, E → B}

Eliminating bad FD X → A (for all A) Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

Eliminating bad FD X → A (for all A) Remarks. Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

Eliminating bad FD X → A (for all A) Remarks. Algorithm Decomposition(X) eliminates the bad FD X→A: Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

Eliminating bad FD X → A (for all A) Remarks. Algorithm Decomposition(X) eliminates the bad FD X→A: * X→A is still an FD in R1=(X+) but now X is a superkey for R1; Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

Eliminating bad FD X → A (for all A) Remarks. Algorithm Decomposition(X) eliminates the bad FD X→A: * X→A is still an FD in R1=(X+) but now X is a superkey for R1; * X→A is not FD in R2=(X∪W) because A is not in X∪W. Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

Eliminating bad FD X → A (for all A) Remarks. Algorithm Decomposition(X) eliminates the bad FD X→A: * X→A is still an FD in R1=(X+) but now X is a superkey for R1; * X→A is not FD in R2=(X∪W) because A is not in X∪W. Does Decomposition(X) change (i.e., lose or add extra) information for R? Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

Eliminating bad FD X → A (for all A) Remarks. Algorithm Decomposition(X) eliminates the bad FD X→A: * X→A is still an FD in R1=(X+) but now X is a superkey for R1; * X→A is not FD in R2=(X∪W) because A is not in X∪W. Does Decomposition(X) change (i.e., lose or add extra) information for R: No. Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

Eliminating bad FD X → A (for all A) Remarks. Algorithm Decomposition(X) eliminates the bad FD X→A: * X→A is still an FD in R1=(X+) but now X is a superkey for R1; * X→A is not FD in R2=(X∪W) because A is not in X∪W. Does Decomposition(X) change (i.e., lose or add extra) information for R: No. Can R1 and R2 still have bad FDs? Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

Eliminating bad FD X → A (for all A) Remarks. Algorithm Decomposition(X) eliminates the bad FD X→A: * X→A is still an FD in R1=(X+) but now X is a superkey for R1; * X→A is not FD in R2=(X∪W) because A is not in X∪W. Does Decomposition(X) change (i.e., lose or add extra) information for R: No. Can R1 and R2 still have bad FDs: Yes. Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

Boyce-Codd Normal Form (BCNF) Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey.

Boyce-Codd Normal Form (BCNF) Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.)

Boyce-Codd Normal Form (BCNF) Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.) Example 1. Likes(drinker, addr, zip, beer, manf) FD’s: T = {drinker → addr, addr → zip, beer → manf}

Boyce-Codd Normal Form (BCNF) Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.) Example 1. Likes(drinker, addr, zip, beer, manf) FD’s: T = {drinker → addr, addr → zip, beer → manf} The only key is {drinker, beer}.

Boyce-Codd Normal Form (BCNF) Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.) Example 1. Likes(drinker, addr, zip, beer, manf) FD’s: T = {drinker → addr, addr → zip, beer → manf} The only key is {drinker, beer}. In each FD, the left side is not a superkey.

Boyce-Codd Normal Form (BCNF) Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.) Example 1. Likes(drinker, addr, zip, beer, manf) FD’s: T = {drinker → addr, addr → zip, beer → manf} The only key is {drinker, beer}. In each FD, the left side is not a superkey. Any one of these FD’s shows Likes is not in BCNF

Boyce-Codd Normal Form (BCNF) Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.) Example 2. Beers(name, manf, manfAddr) FD’s: T = {name → manf, manf → manfAddr}

Boyce-Codd Normal Form (BCNF) Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.) Example 2. Beers(name, manf, manfAddr) FD’s: T = {name → manf, manf → manfAddr} The only key is {name}.

Boyce-Codd Normal Form (BCNF) Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.) Example 2. Beers(name, manf, manfAddr) FD’s: T = {name → manf, manf → manfAddr} The only key is {name}. name → manf does not violate BCNF.

Boyce-Codd Normal Form (BCNF) Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.) Example 2. Beers(name, manf, manfAddr) FD’s: T = {name → manf, manf → manfAddr} The only key is {name}. name → manf does not violate BCNF. However, manf → manfAddr violates BCNF.