Comp 5311 Database Management Systems. 5. Functional Dependencies Exercises

Similar documents
Design theory for relational databases

Relational-Database Design

CSE 132B Database Systems Applications

Chapter 7: Relational Database Design

Chapter 7: Relational Database Design. Chapter 7: Relational Database Design

Chapter 3 Design Theory for Relational Databases

Chapter 8: Relational Database Design

UVA UVA UVA UVA. Database Design. Relational Database Design. Functional Dependency. Loss of Information

Relational Design Theory II. Detecting Anomalies. Normal Forms. Normalization

Review: Keys. What is a Functional Dependency? Why use Functional Dependencies? Functional Dependency Properties

Information Systems for Engineers. Exercise 8. ETH Zurich, Fall Semester Hand-out Due

Relational Database Design

Relational Design Theory

Relational Design Theory I. Functional Dependencies: why? Redundancy and Anomalies I. Functional Dependencies

FUNCTIONAL DEPENDENCY THEORY. CS121: Relational Databases Fall 2017 Lecture 19

Databases Lecture 8. Timothy G. Griffin. Computer Laboratory University of Cambridge, UK. Databases, Lent 2009

Lecture 6 Relational Database Design

Design Theory for Relational Databases. Spring 2011 Instructor: Hassan Khosravi

Shuigeng Zhou. April 6/13, 2016 School of Computer Science Fudan University

Chapter 11, Relational Database Design Algorithms and Further Dependencies

Design Theory for Relational Databases

CSC 261/461 Database Systems Lecture 13. Spring 2018

Design Theory: Functional Dependencies and Normal Forms, Part I Instructor: Shel Finkelstein

Consider a relation R with attributes ABCDEF GH and functional dependencies S:

Normal Forms Lossless Join.

Normal Forms (ii) ICS 321 Fall Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa

Relational Database Design

Database Design: Normal Forms as Quality Criteria. Functional Dependencies Normal Forms Design and Normal forms

Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "

Relational Database Design Theory Part II. Announcements (October 12) Review. CPS 116 Introduction to Database Systems

Schema Refinement & Normalization Theory

Functional Dependencies and Normalization

INF1383 -Bancos de Dados

LOGICAL DATABASE DESIGN Part #1/2

Functional Dependencies

Databases 2012 Normalization

CSE 344 AUGUST 6 TH LOSS AND VIEWS

Database Normaliza/on. Debapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata

Relational Database Design

Functional Dependencies & Normalization. Dr. Bassam Hammo

CSC 261/461 Database Systems Lecture 11

12/3/2010 REVIEW ALGEBRA. Exam Su 3:30PM - 6:30PM 2010/12/12 Room C9000

Chapter 3 Design Theory for Relational Databases

CSIT5300: Advanced Database Systems

Schema Refinement and Normal Forms. Chapter 19

Schema Refinement and Normal Forms Chapter 19

SCHEMA NORMALIZATION. CS 564- Fall 2015

CSE 344 MAY 16 TH NORMALIZATION

Functional Dependencies and Normalization. Instructor: Mohamed Eltabakh

DESIGN THEORY FOR RELATIONAL DATABASES. csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Meraji Winter 2018

CS122A: Introduction to Data Management. Lecture #13: Relational DB Design Theory (II) Instructor: Chen Li

Functional Dependency Theory II. Winter Lecture 21

Consider a relation R with attributes ABCDEF GH and functional dependencies S:

CSE 303: Database. Outline. Lecture 10. First Normal Form (1NF) First Normal Form (1NF) 10/1/2016. Chapter 3: Design Theory of Relational Database

Design Theory for Relational Databases

Database Design and Normalization

Introduction to Management CSE 344

Schema Refinement and Normal Forms

Normal Forms. Dr Paolo Guagliardo. University of Edinburgh. Fall 2016

Schema Refinement & Normalization Theory: Functional Dependencies INFS-614 INFS614, GMU 1

10/12/10. Outline. Schema Refinements = Normal Forms. First Normal Form (1NF) Data Anomalies. Relational Schema Design

But RECAP. Why is losslessness important? An Instance of Relation NEWS. Suppose we decompose NEWS into: R1(S#, Sname) R2(City, Status)

11/1/12. Relational Schema Design. Relational Schema Design. Relational Schema Design. Relational Schema Design (or Logical Design)

CSE 344 AUGUST 3 RD NORMALIZATION

CS54100: Database Systems

CS 186, Fall 2002, Lecture 6 R&G Chapter 15

Introduction to Data Management CSE 344

Schema Refinement and Normal Forms

Introduction to Data Management. Lecture #7 (Relational DB Design Theory II)

Constraints: Functional Dependencies

Functional Dependencies

Database Design and Implementation

Introduction to Database Systems CSE 414. Lecture 20: Design Theory

Homework 2 (by Prashasthi Prabhakar) Due: Wednesday Sep 20, 11:59pm

FUNCTIONAL DEPENDENCY THEORY II. CS121: Relational Databases Fall 2018 Lecture 20

Schema Refinement and Normalization

CSC 261/461 Database Systems Lecture 12. Spring 2018

CAS CS 460/660 Introduction to Database Systems. Functional Dependencies and Normal Forms 1.1

Schema Refinement and Normal Forms. Why schema refinement?

Introduction to Data Management CSE 344

Relational Design: Characteristics of Well-designed DB

The Evils of Redundancy. Schema Refinement and Normal Forms. Example: Constraints on Entity Set. Functional Dependencies (FDs) Example (Contd.

The Evils of Redundancy. Schema Refinement and Normal Forms. Example: Constraints on Entity Set. Functional Dependencies (FDs) Refining an ER Diagram

Schema Refinement. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

Schema Refinement and Normal Forms. The Evils of Redundancy. Schema Refinement. Yanlei Diao UMass Amherst April 10, 2007

Schema Refinement and Normal Forms. The Evils of Redundancy. Functional Dependencies (FDs) CIS 330, Spring 2004 Lecture 11 March 2, 2004

Functional Dependencies. Getting a good DB design Lisa Ball November 2012

Functional Dependency and Algorithmic Decomposition

The Evils of Redundancy. Schema Refinement and Normalization. Functional Dependencies (FDs) Example: Constraints on Entity Set. Refining an ER Diagram

Introduction. Normalization. Example. Redundancy. What problems are caused by redundancy? What are functional dependencies?

CS322: Database Systems Normalization

CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen

11/6/11. Relational Schema Design. Relational Schema Design. Relational Schema Design. Relational Schema Design (or Logical Design)

Introduction to Data Management. Lecture #6 (Relational Design Theory)

Homework 2 (by Prashasthi Prabhakar) Solutions Due: Wednesday Sep 20, 11:59pm

Schema Refinement and Normal Forms

Databases 2011 The Relational Algebra

Schema Refinement and Normal Forms. The Evils of Redundancy. Functional Dependencies (FDs) [R&G] Chapter 19

Schema Refinement and Normal Forms

The Evils of Redundancy. Schema Refinement and Normal Forms. Functional Dependencies (FDs) Example: Constraints on Entity Set. Example (Contd.

Transcription:

Comp 5311 Database Management Systems 5. Functional Dependencies Exercises 1

Assume the following table contains the only set of tuples that may appear in a table R. Which of the following FDs hold in R: tuple X Y V W 1 x 1 y 1 v 1 w 1 2 x 1 y 1 v 2 w 2 3 x 2 y 1 v 1 w 3 {X} {X} Yes trivial (holds in any table) {X} {Y} Yes all values of Y are identical {X} {V} No see first two rows {X} {W} No same as before 2 4 x 2 y 1 v 3 w 4 {Y} {X} No (same for {Y} {V,W}) {W} {X} Yes all W values are different {X,V} {Y} Yes X alone determines Y {Y,V} {X} No see rows 1 and 3

In the previous example, we assumed that we know all possible records in a table, which is not usually true. In general by looking at an instance of a relation, we can only tell FDs that are NOT satisfied. List 5 FDs that are not satisfied in the table: {B} {A} A B C a 1 b 1 c 1 a 1 b 1 c 2 a 2 b 1 c 1 a 2 b 1 c 3 {B} {C} {C} {A} {A} {C} {A,B} {C} 3

In reality, FDs are given implicitly in the form of constraints when designing a database. Let a relation R(Title, Theater, City) where title is the name of a movie, theater is the name of a theater playing the movie and city is the city where the theater is located. We are given the following constraints: Two different cities cannot have theaters with the same name. Two different theaters in the same city cannot play the same movie. A theater can play many movies (e.g., cineplex). Write the set of functional dependencies implied by the above assumptions. {Theater} {City} (if we know the theater, we know the city where it is located the opposite is not true as a city can have many theaters) {City, Title} {Theater} Can you identify the candidate key(s) City, Title and Theater, Title 4

We want to create the database for a bank that contains accounts (A), branches (B) and customers (C). We are given the following constraints: An account cannot be shared by multiple customers. Two different branches do not have the same account. Each customer can have at most one account in a branch (but different accounts in different branches). Write the functional dependencies implied by the above constraints {Account} {Customer} {Account} {Branch} {Customer, Branch} {Account} Write the candidate key(s): Customer, Branch and Account 5

Let R(A,B,C). Assume that we do not know the keys of the table. How would you test if A is a candidate key of R with a SQL query? SELECT A FROM R GROUP BY A HAVING COUNT(*)>1 If this query gives a non-empty result, then A is not a key. If the result is empty we cannot be sure. What about testing if the dependency {A} {B} holds in R? Same as before but replace the last line with HAVING COUNT(DISTINCT B)>1 6

A B C D F Which are the FDs implied in the above ER diagram? E A B A C C A D C EC F 7

Let the rule: if X Z and Y Z, then X Y Show that this rule is not sound (correct) with a counterexample. Lets use R(X,Y,Z). We want to find an instance of R where the rule is violated. Lets say that R contains just two tuples: (x1, y1, z1) (x1, y2, z1) {X} {Z} and {Y} {Z} hold, but {X} {Y} is not true. 8

Consider a relation R(X,Y,U,V,W) with the following set of dependencies {{X} {Y}, {U,V} {W}, {V} {X}} Find the closure of each attribute: X+={X,Y} Y+={Y} U+={U} V+={V,X,Y} W+={W} What is the primary key of R?: UV 9

R = (A, B, C, G, H, I) F = (A B A C CG H CG I B H} Is AG a (super)key of R given F? (AG + ) 1. Result= AG 2. Result= ABCG (A C; A B and A AG) 3. Result= ABCGH (CG H and CG AGBC) 4. Result=ABCGHI (CG I and CG AGBCH) Is AG a candidate key? 1. AG R 2. Does A + R? 3. Does G + R? 10

Let the relation schema R(A,B,C,D,E) and the set of functional dependencies: F = {{A} {B}, {A,B} {C}, {D} {A,C}}: Find the canonical cover of F {A B, AB C, D AC} {A B, A C, D AC} {A BC, D A} Compute the attribute closures A+ = {A,B,C} B+ = {B}, C+ = {C} D+ = {D,A,B,C} E+ = {E} What is the primary key of R? DE 11

Let R(A,B,C,D,E), the FD {A} {B,C} and the decomposition: R1(A,B,C) and R2(A,D,E) Is the decomposition lossless? Yes because the common attribute A is a key for R1 Is the decomposition dependency preserving? Yes, {A} {B,C} is preserved in R1 Is the decomposition R1(A,B,C) and R2(C,D,E) lossless? No C is not a key for any table 12

Let R = (A, B, C, D, E), F = {A BC, CD E, B D, E A} and the decomposition R 1 = (A, B, C) R 2 = (A, D, E) Is the decomposition lossless? Yes because the common attribute A is a key for R1 Is the decomposition dependency preserving? No: we loose CD E and B D 13