Review for Final Exam Lecture Week 14. Problems on Functional Dependencies and Normal Forms.

Slides:



Advertisements
Similar presentations
Schema Refinement: Normal Forms
Advertisements

Schema Refinement: Canonical/minimal Covers
Schema Refinement and Normal Forms
DB Review Session. ER Diagrams 1 Where does the salary attribute belong? Actor id name address birthday Acted In Movie title type year salary.
Normalization 1 Instructor: Mohamed Eltabakh Part II.
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.
CS 440 Database Management Systems Practice problems for normalization.
Normalization theory exercises Dr. Shiyong Lu Department of Computer Science Wayne State University ©copyright 2007, all rights reserved.
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 19.
Classroom Exercise: Normalization
Normalization DB Tuning CS186 Final Review Session.
Normalization DB Tuning CS186 Final Review Session.
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.
Normalization. FarkasCSCE 5202 Reading Assignments  Database Systems The Complete Book: Chapters 3.6, 3.7, 3.8  Following lecture slides are modified.
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.
Department of Computer Science and Engineering, HKUST Slide 1 7. Relational Database Design.
Boyce-Codd Normal Form By: Thanh Truong. Boyce-Codd Normal Form Eliminates all redundancy that can be discovered by functional dependencies But, we can.
1 Lecture 7: Schema refinement: Normalisation
©Silberschatz, Korth and Sudarshan7.1Database System Concepts Chapter 7: Relational Database Design First Normal Form Pitfalls in Relational Database Design.
Databases 1 Seventh lecture. Topics of the lecture Extended relational algebra Normalization Normal forms 2.
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.
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.
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.
CSCI 4333 Database Design and Implementation – Exercise (3) Xiang Lian The University of Texas – Pan American Edinburg, TX
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.
Computing & Information Sciences Kansas State University Tuesday, 27 Feb 2007CIS 560: Database System Concepts Lecture 18 of 42 Tuesday, 27 February 2007.
Functional Dependencies and Normalization 1 Instructor: Mohamed Eltabakh
CS 564 Database Management Systems: Design and Implementation Discussion Session Friday, Sept 18, Apul Jain.
Final Exam Revision Instructor: Mohamed Eltabakh 1.
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:
Announcements Midterm is Nov. 22 (8:15am – 9:45am) Covers until the end of Normalization You answer in the same exam paper Closed-Book, One sheet is allowed.
Third Normal Form (3NF) Zaki Malik October 23, 2008.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 15.
Copyright, Harris Corporation & Ophir Frieder, The Process of Normalization.
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 19.
1 Schema Refinement and Normal Forms Chapter The Evils of Redundancy  Redundancy is at the root of several problems associated with relational.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 19.
© 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.
Normalization and FUNctional Dependencies. Redundancy: root of several problems with relational schemas: –redundant storage, insert/delete/update anomalies.
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
Midterm Review. Main Topics ER model Relational model Relational Database Design (Theory)
CS 440 Database Management Systems
Schedule Today: Next After that Normal Forms. Section 3.6.
Relational Database Design (Discussion Session)
Schema Refinement and Normal Forms
Normalization First Normal Form (1NF) Boyce-Codd Normal Form (BCNF)
Relational Database Design by Dr. S. Sridhar, Ph. D
CS 480: Database Systems Lecture 22 March 6, 2013.
Functional Dependencies and Normalization
Schema Refinement and Normal Forms
Functional Dependencies and Normalization
Schema Refinement and Normalization
Some slides are from Dr. Sara Cohen
Instructor: Mohamed Eltabakh
Functional Dependencies and Normalization
Functional Dependencies and Normalization
CS4222 Principles of Database System
Presentation transcript:

Review for Final Exam Lecture Week 14

Problems on Functional Dependencies and Normal Forms

Problem 1 R = {Broker (B), Office (O), Investor (I), Stock (S), Quantity (Q)} F = { I -> B, IS -> Q, B -> O} a. What are the keys of the relation? b. Is the relation in BCNF? IS -> ISBQO IS is the only key No, because of I->B and B->O

F = { I -> B, IS -> Q, B -> O} Produce a lossless-join, BCNF decomposition of the original relation Is your decomposition dependency-preserving? R1=(I,B), R2 = (I,S,Q,O) R2 is not BCNF (I->O) R21= (I,S,Q), R22= (I,O) No, because of B->O is not preserved. You need a join to enforce it! Problem 1 (contd.)

Problem 2 Consider the relation R=(A,B,C,D,E) and F ={ A->BC, CD->E, B-> D, E-> A} a. Is this schema in 3NF? Note: no attributes appear only on left sides or only on right sides. We start with computing the closure of single attributes: A+ = ABCDE; B+ = BD; C+ = C; D+ = D; E+ = EABCD. It follows that A and E are candidate keys. Now we consider combinations of two attributes: BC+ = BCDEA, BD+ = BD, CD+ = CDEAB. It follows that BC and CD are candidate keys. There are no more combinations to be considered. The candidate keys are: A, E, BC, and CD.

Problem 2 (contd.) Consider the relation R=(A,B,C,D,E) and F ={ A->BC, CD->E, B-> D, E-> A} a. Is this schema in 3NF? The candidate keys are: A, E, BC, and CD. We reduce F in canonical form: F={A->B, A->C, CD->E, B->D, E->A} A->B is in 3NF since A is a key; A->C is in 3NF since A is a key; CD->E is in 3NF since CD is a key; B->D is in 3NF since D is part of a key; E->A is in 3NF since E is a key. It follows that the given schema is in 3NF.

F ={ A->BC, CD->E, B-> D, E-> A} Give a lossless-join, decomposition into BCNF (The relation is not in BCNF, since B is not a key and B->D) ABCDE BD ABCE Also BCNF The decomposition is lossless-join: R1  R2 = {B} key of R1=BD. But it is not d.p. CD->E requires a join! Problem 2 (contd.)

F ={ A->BC, CD->E, B-> D, E-> A} Show that the decomposition R1= (A,B,C), R2 = (A,D,E) is lossless-join, but not dependency- preserving R1  R2 = A, which is a key of both! So, the decomposition is lossless-join But the dependency B->D is not preserved. Problem 2 (contd.)

F ={ A->BC, CD->E, B-> D, E-> A} Show that the decomposition R1= (A,B,C), R2 = (C,D,E) is not lossless-join. R1  R2 = {C} which is not a key of R1 or R2, so the decomposition is not lossless-join. Problem 2 (contd.)

Problem 3 R(A,B,C,D), F={AB->C, C->D, D->A} Is R in BCNF? We need to check if any of the given functional dependencies violates the BCNF: AB+ = ABCD Thus AB->C is in BCNF. C+ = CDA Thus C->D violates the BCNF. D+ = DA Thus D->A violates the BCNF. It follows that R in not in BCNF.

Problem 3 (contd.) R(A,B,C,D), F={AB->C, C->D, D->A} Decompose R into relations that are in BCNF using a lossless join decomposition. From previous analysis: C->D and D->A violate the BCNF. Using C->D, we decompose R into CD and ABC. We need to check whether ABC is in BCNF. We observe that C->A is in F+, and in the projection of F onto ABC. C is not a (super)key for ABC, thus ABC is not in BCNF. We decompose it further into CA and BC. The resulting decomposition CD, CA, and BC is a lossless join decomposition of ABCD into BCNF relations. The decomposition is not dependency preserving. E.g., AB->C is not preserved.

Problem 4 R(A,B,C,D) F = {B->C, B->D} Is R in BCNF? If not, compute a lossless join decomposition of R into BCNF relations. Both dependencies in F violate the BCNF condition since B is not a (super)key. One possible decomposition is R1=BC and R2=ABD (using B->C). B->D holds on R2, and B is not a superkey for R2, so we decompose it further in: R23=BD and R24=AB. The resulting decomposition is: BC, BD, and AB. This decomposition preserves dependencies: (F1  F23)+ = F+

Problem 5 Answer: B and C are consistent with Country -> Capitol

Final Exam Comprehensive, closed books; Topics: –ER Diagrams; –Relational Database schemas; –Key constraints, participation constraints, weak entities, etc; –Relational algebra; –SQL (including GROUP BY and HAVING clauses, aggregate operators, set comparison operators, nested queries, etc.); –Functional dependencies; –Normal forms (BCNF, 3NF) and related decomposition techniques.

Discussion of Problems in Sample Final

SELECT C.Instructor-SSn, sum(decode(S.Status,’Grad’,1,0))/count(*) as Percent FROM Class C, Enrollment E, Student S WHERE (C.Class-no=E.Class-no) AND (E.Student-Ssn=S.Ssn) GROUP BY C.Instructor-SSn Problem 2 (4)

SELECT C.D-code, C.num-st FROM (SELECT D.D-code, count(*) as num-st FROM Department D, Student S WHERE D.D-code=S.Major GROUP BY D.D-code) C WHERE C.num-st <= ALL (SELECT C.num-st FROM C) Problem 2 (5)