CSE 444 Midterm Test

Similar documents
The University of British Columbia

Database Management

The Relational Data Model

CSIT5300: Advanced Database Systems

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Winter 2009 Lecture 4 - Schema Normalization

Functional Dependencies CS 1270

Design Theory for Relational Databases

Normalization. Murali Mani. What and Why Normalization? To remove potential redundancy in design

CSE 444, Fall 2010, Midterm Examination 10 November 2010

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2009 Lecture 3 - Schema Normalization

CS411 Database Systems. 05: Relational Schema Design Ch , except and

BCNF. Yufei Tao. Department of Computer Science and Engineering Chinese University of Hong Kong BCNF

COMP7640 Assignment 2

COSC Dr. Ramon Lawrence. Emp Relation

Midterm Exam (Version B) CS 122A Spring 2017

CSE 444, Winter 2011, Midterm Examination 9 February 2011

CS 461: Database Systems. Final Review. Julia Stoyanovich

The University of British Columbia

Final Review. Zaki Malik November 20, 2008

SCHEMA REFINEMENT AND NORMAL FORMS

SOLUTIONS TO THE FINAL EXAMINATION Introduction to Database Design Spring 2011

A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

CSE 562 Database Systems

UNIT 3 DATABASE DESIGN

MIDTERM EXAMINATION Spring 2010 CS403- Database Management Systems (Session - 4) Ref No: Time: 60 min Marks: 38

Lectures 5 & 6. Lectures 6: Design Theory Part II

LOGICAL DATABASE DESIGN Part #2/2

The Relational Data Model. Functional Dependencies. Example. Functional Dependencies

Functional Dependencies and Finding a Minimal Cover

Functional Dependencies and Normalization

Review: Attribute closure

Fundamentals of Database Systems

Homework 6: FDs, NFs and XML (due April 13 th, 2016, 4:00pm, hard-copy in-class please)

Example Examination. Allocated Time: 100 minutes Maximum Points: 250

IMPORTANT: Circle the last two letters of your class account:

Exam I Computer Science 420 Dr. St. John Lehman College City University of New York 12 March 2002

CS 564 Midterm Review

Solutions. Updated of 7

CSE 344 Final Examination

Bachelor in Information Technology (BIT) O Term-End Examination

Database Management Systems Paper Solution

Schema Refinement and Normal Forms

CSCI DBMS Spring 2017 Final Examination. Last Name: First Name: Student Id:

6 February 2014 CSE-3421M Test #1 w/ answers p. 1 of 14. CSE-3421M Test #1. Design

Desired properties of decompositions

CSE 444 Midterm Exam

Exam. Question: Total Points: Score:

Database Systems. Basics of the Relational Data Model

CSE 344 Midterm. Monday, Nov 4, 2013, 9:30-10:20. Question Points Score Total: 100

Lectures 12: Design Theory I. 1. Normal forms & functional dependencies 2/19/2018. Today s Lecture. What you will learn about in this section

Database Management

Part II: Using FD Theory to do Database Design

Name: Database Systems ( 資料庫系統 ) Midterm exam, November 15, 2006

Relational Model, Relational Algebra, and SQL

Introduction to Database Systems CSE 544. Lecture #2 January 16, 2007

Introduction to Database Systems. Announcements CSE 444. Review: Closure, Key, Superkey. Decomposition: Schema Design using FD

Birkbeck. (University of London) BSc/FD EXAMINATION. Department of Computer Science and Information Systems. Database Management (COIY028H6)

Databases -Normalization I. (GF Royle, N Spadaccini ) Databases - Normalization I 1 / 24

Sample Exam for CSE 480 (2016)

E-R diagrams and database schemas. Functional dependencies. Definition (tuple, attribute, value). A tuple has the form

CSCI 403: Databases 13 - Functional Dependencies and Normalization

Lecture 11 - Chapter 8 Relational Database Design Part 1

Functional dependency theory

Babu Banarasi Das National Institute of Technology and Management

Final Examination Computer Science 420 Dr. St. John Lehman College City University of New York 21 May 2002

Case Study: Lufthansa Cargo Database

Normal Forms. Winter Lecture 19

This lecture. Databases -Normalization I. Repeating Data. Redundancy. This lecture introduces normal forms, decomposition and normalization.

Birkbeck. (University of London) BSc/FD EXAMINATION. Department of Computer Science and Information Systems. Database Management (COIY028H6)

CSCI 5333 DBMS Fall 2017 Final Examination. Last Name: First Name: Student Id:

Total No. of Questions :09] [Total No. of Pages : 02. II/IV B.Tech. DEGREE EXAMINATIONS, NOV/DEC Second Semester CSE/IT DBMS

Presentation on Functional Dependencies CS x265

BIRKBECK (University of London)

The University of British Columbia

Chapter 8: Relational Database Design

Exam II Computer Programming 420 Dr. St. John Lehman College City University of New York 20 November 2001

Normalization is based on the concept of functional dependency. A functional dependency is a type of relationship between attributes.

Homework 3: Relational Database Design Theory (100 points)

DATABASE MANAGEMENT SYSTEM SHORT QUESTIONS. QUESTION 1: What is database?

Exercise 9: Normal Forms

Applied Databases. Sebastian Maneth. Lecture 5 ER Model, normal forms. University of Edinburgh - January 25 th, 2016

customer = (customer_id, _ customer_name, customer_street,

CS403- Database Management Systems Solved MCQS From Midterm Papers. CS403- Database Management Systems MIDTERM EXAMINATION - Spring 2010

Relational Database Design (II)

Introduction to Databases, Fall 2003 IT University of Copenhagen. Lecture 4: Normalization. September 16, Lecturer: Rasmus Pagh

Homework 6. Question Points Score Query Optimization 20 Functional Dependencies 20 Decompositions 30 Normal Forms 30 Total: 100

Unit 3 : Relational Database Design

. : B.Sc. (H) Computer Science. Section A is compulsory. Attempt all parts together. Section A. Specialization lattice and Specialization hierarchy

Applied Databases. Sebastian Maneth. Lecture 5 ER Model, Normal Forms. University of Edinburgh - January 30 th, 2017

NORMAL FORMS. CS121: Relational Databases Fall 2017 Lecture 18

Homework 6: FDs, NFs and XML (due April 15 th, 2015, 4:00pm, hard-copy in-class please)

3.1. Keys: Super Key, Candidate Key, Primary Key, Alternate Key, Foreign Key

5 Normalization:Quality of relational designs

Normalization 03. CSE3421 notes

L Information Systems for Engineers. Final exam. ETH Zurich, Autumn Semester 2017 Friday

DATABASTEKNIK - 1DL116

Chapter 10. Normalization. Chapter Outline. Chapter Outline(contd.)

Examination examples

Informal Design Guidelines for Relational Databases

Examination paper for TDT4145 Data Modelling and Database Systems

Transcription:

CSE 444 Midterm Test Spring 2007 Name: Total time: 50 Question 1 /40 Question 2 /30 Question 3 /30 Total /100 1

1 SQL [40 points] Consider a database of social groups that allows people to become members of groups: a person can be a member of several groups and each group maintains a list of pictures that are accessible to all members. In addition to the groups, the database also maintains a list of friends. The schema is: MEMBER(personName, groupname) PICTURE(groupName, picture) /* picture = primary key */ FRIEND(personName1, personname2) PICTURE stores for each picture the name of the group that owns that picture. The FRIEND table is symmetric, i.e. if X is friend with Y then Y is friend with X. Every person is a member of at least one group. 1.1 Write a SQL query that computes for every person the total number of pictures they can access through their group memberships. That is, a person X can access a picture Y if X is a member of some group Z and Z owns the picture Y. You need to turn in a SQL query that returns a result like this: Fred, 12 Joe, 7 Sue, 0 Rick, 9... SELECT personname, COUNT(*) FROM member LEFT OUTER JOIN picture ON member.groupname = picture.groupname GROUP BY (personname) Another solution: SELECT personname, COUNT(DISTINCT picture) FROM member LEFT OUTER JOIN picture ON member.groupname = picture.groupname GROUP BY (personname) Note: If you use normal join instead of LEFT OUTER JOIN then you will miss those people who cannot access any picture (e.g. Sue in the example above). 2

1.2 A cool person is one that has at least 40 friends. Write a SQL query that returns all the cool persons in the database. You need to turn in a SQL query that computes a list of names. SELECT personname1 FROM friend GROUPBY personname1 HAVING (COUNT(*) >= 40) Another solution: SELECT personname1 FROM friend GROUPBY personname1 HAVING (COUNT(DISTINCT personname2) >= 40) 1.3 The marketing department has decided to recommend people to subscribe to additional groups. However, they do not want to issue phony recommendations. They would like to recommend to a person X to subscribe to a group Y if all X s friends are members of the group Y, but X is not a member of Y. Write a SQL query that computes for each person X the set of groups to recommend that that person subscribes. You need to turn in a SQL query that returns a list of (person, group) pairs. SELECT m.personname, g.groupname FROM member m, member g WHERE NOT EXISTS ( SELECT * FROM friend f WHERE m.personname=f.personname1 and NOT EXISTS ( SELECT * FROM member mf WHERE mf.personname = f.personname2 and mf.groupname = g.groupname)) EXCEPT (SELECT * FROM member) 3

1.4 Create a new table ACCESS(personName, picture) that lists for each person the list of pictures that they can access. A person X can access a picture Y either if X belongs to a group that owns Y, or of X has a friend Z who belongs to a group that owns Y. Write SQL statements that insert the corresponding tuples in ACCESS. You need to turn in one or more INSERT queries. CREATE TABLE ACCESS ( personname VARCHAR(50) REFERENCES (member.personname), picture INT REFERENCES (picture.picture)) INSERT INTO ACCESS SELECT DISTINCT m.personname, p.picture FROM member m, member m1, picture p, friend f WHERE m.groupname = p.groupname OR (m1.groupname = p.groupname AND m1.personname = f.personname2 AND m.personname = f.personname1) Another solution: INSERT INTO ACCESS SELECT DISTINCT m.peronsname, p.picture FROM member m, picture p WHERE m.groupname = p.groupname INSERT INTO ACCESS SELECT DISTINCT f.personname1, p.picture FROM friend f, member m, picture p WHERE f.personname2 = m.personname and m.groupname = p.groupname Note: In the second solution, some tuples may be inserted more than once (why?). To fix it, change the second query to INSERT INTO ACCESS SELECT DISTINCT f.personname1, p.picture FROM friend f, member m, picture p WHERE f.personname2 = m.personname and m.groupname = p.groupname and not exists (select * from access a where f.personname1=a.personname and...) 4

2 Conceptual Design [30 points] Consider an application that needs to manage data for a travel agency. It needs to store the following entities and relationships: 2.1 Hotels: have attributes name, address, price Resorts: are Hotels, that also have an attribute minimum-stay Activities: have attributes name, season Has: is a relationship between Resorts and Activities Design an E/R diagram for this application. name address price Hotel ISA name Resort has Activity minstay season Assumption: activities are uniquely identified their names (you could make other assumptions; it s OK as long as you stated them clearly). 5

2.2 Write the CREATE TABLE statement for creating the SQL tables. You may choose very simple atomic datatypes for the attributes. Indicate all keys and foreign keys. CREATE TABLE hotel ( name VARCHAR(50), address VARCHAR(100) PRIMARY KEY, price INT ); CREATE TABLE resort ( address PRIMARY KEY REFERENCES hotel.address, minstay INT ); CREATE TABLE activity ( name VARCHAR(50) PRIMARY KEY, season VARCHAR(50) ); CREATE TABLE has ( resortaddress REFERENCES resort.address, activityname REFERENCES activity.name ) 6

3 Functional dependencies and normal forms [30 points] Consider a table R(A,B,C,D). Recall that a set of attributes X is a superkey if X + = ABCD; a set X is a key if X is a superkey and no subset of X is a superkey; it is closed if X + = X. 3.1 Give a set of functional dependencies that satisfies the following conditions: the closed sets are AB, CD, and the keys are AD and BC. {A B,B A,C D,D C} Note: The question is a bit ambiguous. You cannot find a set of functional dependencies such that AB and CD are the ONLY closed sets and AD and BC are the ONLY keys. In the solution above, AB and CD are the only closed sets; however, AC and BD are also keys. Therefore, I also accept solutions in which there are other closed sets and keys (i.e., as long as AB and CD are closed sets and AC and BD are keys, you are in a good shape). 3.2 For each of the statements below indicate if they are true of false. You need to answer only true or false and do not need to justify your answer. X and Y denote sets of attributes. (a) If AB is a key then ABC cannot be closed. TRUE (ABC + = ABCD in this case). (b) If AB is closed then ABC cannot be a key. FALSE (Consider the case where there is only one dependency: ABC ABCD). (c) If X,Y are closed then X Y is closed.false (Consider the case where ther is only one dependency AB C and X = {A},Y = {B}). (d) If X,Y are closed then X Y is closed. TRUE (Let Z = X Y. If Z is not closed then there is an attribute A Z + \Z. Since A / Z, either A / X or A / Y. Without loss of generality, assume that A / X. Remember that A Z +. Since Z X, Z + X +. Therefore, A X +. This means X + X, i.e. X is not closed (contradiction!)). 7

3.3 Consider the following FDs: B A C B Decompose the table in Boyce Codd Normal Form (BCNF). Show your decomposition steps. R(A,B,C,D) B+ = AB ABCD R1(A,B) (BCNF) R2(B,C,D) C+ = BC BCD R1(B,C) (BCNF) R1(B,D) (BCNF) End of paper. Good luck! 8