Non Trivial FD. Candidate Key FD’s that Hold on S.

Slides:



Advertisements
Similar presentations
CS 319: Theory of Databases
Advertisements

CT Z Y 2 TGG X 1 4 I. Smith T. Yang B. Stromback E. Williams Cam. Jones E. Spyhalski M. Johnson T. Long N. Norman AJ Johnson D. Tolkinen J. Lundgren S.
Chapter 16: Relational Database Design and Further Dependencies
Schema Refinement: Normal Forms
Schema Refinement: Canonical/minimal Covers
Functional Dependencies- Examples
Prof. Sin-Min Lee Department of Computer Science
Functional Dependencies- Examples
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Relational Database Design Algorithms and Further Dependencies.
Lecture 21 CS 157 B Revision of Midterm3 Prof. Sin-Min Lee.
Normalization 1 Instructor: Mohamed Eltabakh Part II.
Normalization Decomposition techniques for ensuring: Lossless joins Dependency preservation Redundancy avoidance We will look at some normal forms: Boyce-Codd.
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.
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.
CS 440 Database Management Systems Practice problems for normalization.
Review for Final Exam Lecture Week 14. Problems on Functional Dependencies and Normal Forms.
Normalization theory exercises Dr. Shiyong Lu Department of Computer Science Wayne State University ©copyright 2007, all rights reserved.
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.
1 Normalization. 2 Normal Forms v If a relation is in a certain normal form (BCNF, 3NF etc.), it is known that certain kinds of redundancies are avoided/minimized.
©Silberschatz, Korth and Sudarshan Relational Database Design First Normal Form Pitfalls in Relational Database Design Functional Dependencies Decomposition.
7.1 Chapter 7: Relational Database Design. 7.2 Chapter 7: Relational Database Design Features of Good Relational Design Atomic Domains and First Normal.
Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Chapter 7: Relational Database Design First Normal.
CS Algorithm : Decomposition into 3NF  Obviously, the algorithm for lossless join decomp into BCNF can be used to obtain a lossless join decomp.
Classroom Exercise: Normalization
Normalization DB Tuning CS186 Final Review Session.
Normalization DB Tuning CS186 Final Review Session.
Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Chapter 7: Relational Database Design First Normal.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. Relational Database Design - part 2 - Database Management Systems I Alex Coman,
CMSC424: Database Design Instructor: Amol Deshpande
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.
1 CMSC424, Spring 2005 CMSC424: Database Design Lecture 9.
Decomposition By Yuhung Chen CS157A Section 2 October
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.
Department of Computer Science and Engineering, HKUST Slide 1 7. Relational Database Design.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts Chapter 7: Relational Database Design First Normal Form Pitfalls in Relational Database Design.
Decompositions uDo we need to decompose a relation? wSeveral normal forms for relations. If schema in these normal forms certain problems don’t.
Relational Database Design by Relational Database Design by Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING.
Normal Forms1. 2 The Problems of Redundancy Redundancy is at the root of several problems associated with relational schemas: Wastes storage Causes problems.
Chapter 8: Relational Database Design First Normal Form First Normal Form Functional Dependencies Functional Dependencies Decomposition Decomposition Boyce-Codd.
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.
Functional Dependencies An example: loan-info= Observe: tuples with the same value for lno will always have the same value for amt We write: lno  amt.
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.
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 1 Instructor: Mohamed Eltabakh
CS 564 Database Management Systems: Design and Implementation Discussion Session Friday, Sept 18, Apul Jain.
R EVIEW. 22 Exam Su 3:30PM - 6:30PM 2010/12/12 Room C9000.
Final Exam Revision Instructor: Mohamed Eltabakh 1.
Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Chapter 7: Relational Database Design First Normal.
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.
Chapter 7 Functional Dependencies
Copyright, Harris Corporation & Ophir Frieder, The Process of Normalization.
CS 338Database Design and Normal Forms9-1 Database Design and Normal Forms Lecture Topics Measuring the quality of a schema Schema design with normalization.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
Huffman code and Lossless Decomposition Prof. Sin-Min Lee Department of Computer Science.
© 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.
Normalization and FUNctional Dependencies. Redundancy: root of several problems with relational schemas: –redundant storage, insert/delete/update anomalies.
Normal Forms Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems June 18, 2016 Some slide content courtesy of Susan Davidson.
Schedule Today: Next After that Normal Forms. Section 3.6.
Relational Database Design (Discussion Session)
Normalization First Normal Form (1NF) Boyce-Codd Normal Form (BCNF)
CS 480: Database Systems Lecture 22 March 6, 2013.
Functional Dependencies and Normalization
Designing Relational Databases
Instructor: Mohamed Eltabakh
Functional Dependencies and Normalization
Functional Dependencies and Normalization
CS4222 Principles of Database System
Presentation transcript:

Non Trivial FD

Candidate Key

FD’s that Hold on S

3NF Consider R = {A, B, C, D, E, F, G, H} with a set of FDs F = {CD→A, EC→H, GHB→AB, C→D, EG→A, H→B, BE→CD, EC→B} The candidate keys are: {BEFG, CEFG, EFGH}

F = {CD→A, EC→H, GHB→AB, C→D, EG→A, H→B, BE→CD, EC→B} No, R w.r.t. F is NOT in 3NF, because CD→A violates the 3NF requirements. i.e. CD→A is not trivial FD CD is not a superkey CD is not a key, but A is not part of any key of R either

Binary Decomposition Approach Considering R: Keys ={BEFG, CEFG, EFGH} F = {CD→A, EC→H, GHB→AB, C→D, EG→A, H→B, BE→CD, EC→B} Decomposition #1: CD→A is a violating FD R is decomposed into R1 and R2: R1 (A,C,D): We need to project FDs F onto relation R1: A+ = A C+ = CDA (C →DA) D+ = D AC+ = ACD (AC→D) AD+ = AD CD+ = CDA (CD → A) So, F1 = {C→DA, AC→D, CD→A}

R2 ( B,C,D,E,F,G,H): In general, we should project F onto R2. However, if we look carefully, we can easily see that the only difference between R and R2 is attribute A. Attribute A has never appeared on LHS of any FD. So, removing it won’t make any change in F2. So, F2={EC→H, GHB→B, C→D, H→B, BE→CD, EC→B} FDs that are lost in Decomposition #1 are: Lost = {GHB→A, EG→A} Do we need further decomposition?

Consider R1(A,C,D): F1 = {C→DA, AC→D, CD→A} Since C+=ACD, C is a key. C (in C→DA), CD (in CD→A), and AC (in AC→D) are key/super keys. Therefore, we have no violating FD. (So, we are done with this branch.) Consider R2: F2={EC→H, C→D, H→B, BE→CD, EC→B} Keys of R2 = Keys of R = {BEFG, CEFG, EFGH} EC→H is not a violating FD, since H is part of a key. C→D is a violating FD, since C is not a super key and D is not part of any key. So, further decomposition is needed.

Decomposition #2: C→D is a violating FD R2 is decomposed into R21 and R22: R21 (C, D): We need to project F2 onto relation R21: C+=CD D+=D So, F21={C→D} R22 (B,C,E,F,G,H): In general, we should project F2 onto R22. However, if we look carefully, we can easily see that the only difference between R2 and R22 is attribute D. Attribute D has never appeared on LHS of any FD. So, removing it won’t make any change in F22. So, F22 = {EC→H, H→B, BE→C, EC→B}

FDs that are lost in Decomposition #2 is: Lost = {BE→D} So, overall, we’ve lost the following FDs: Lost = {GHB→A, EG→A, BE→D} Do we need further decomposition? Consider R21(C,D): F21={C→D} Since C+=CD, C is a key. Therefore, we have no violating FD. (So, we are done with this branch.) Consider R22(B,C,E,F,G,H): Keys of R22 = Keys of R2 = {BEFG, CEFG, EFGH}

F22 = {EC→H, H→B, BE→C, EC→B} EC→H is not a violating FD since H is part of a key. H→B is not a violating FD since B is part of a key. BE→C is not a violating FD since C is part of a key. EC→B is not a violating FD since B is part of a key. So, we are done with this branch. Overall, we have: R1 (A, C, D)F1 = {C→DA, AC→D, CD→A} R21 (C, D)F21 = {C→D} R22 (B, C, E, F, G, H)F22 = {EC→H, H→B, BE→C, EC→B}

Since R1 includes R21 we might want to remove R21. This is a loss-less join decomposition, but it is not dependency preserving. To make the decomposition dependency preserving, we need to add the lost FDs as new relations. The lost FDs are: Lost = {GHB→AB, EG→A, BE→D} So, we add three relations: L1(A, B, G, H) FL1 = {GHB→AB} L2(A, E, G)FL2 = {EG→A} L3(B, D, E)FL3 = {BE→D}

Synthesis Approach R = {A, B, C, D, E, F, G, H} with a set of FDs F = {CD→A, EC→H, GHB→AB, C→D, EG→A, H→B, BE→CD, EC→B} The candidate keys are {BEFG, CEFG, EFGH} Canonical cover for F is: FC = {C→AD, EC→H, GH→A, EG→A, H→B, BE→C}

Now, we create the relations: R1 = {A, C, D} F1 = {C→AD} R2 = {E, C, H} F2 = {EC→H} R3 = {A, G, H} F3 = {GH→A} R4 = {A, E, G} F4 = {EG→A} R5 = {B, H} F5 = {H→B} R6 = {B, C, E} F6 = {BE→C} Now, we need to check if at least one of the keys exists in the above relations. The candidate keys are {BEFG, CEFG, EFGH}

Since none of these keys is in the relations, this decomposition is not lossless. So, we need to add an extra relation containing those attributes that form any key of R: R7 = {B, E, F, G}F7 = { }

Check lossless join Check if the decomposition of R(A, B, C, D, E, F, G) with the set of FDs F={C→AD, E→G, FG→A, EF→A, G→B, BE→C} into the following relations is lossless join. R1 = {A, C, D} R2 = {E, C, G} R3 = {A, F, G} R4 = {A, E, F} R5 = {B, G} R6 = {B, C, E}

Step 1- Table initialization

Round 1

Round 2