Midterm Exam (Version B) CS 122A Spring 2017

Similar documents
Midterm Exam #1 Version A CS 122A Winter 2017

Midterm Exam #1 Version B CS 122A Winter 2017

Midterm Exam #2 (Version A) CS 122A Winter 2017

Midterm Exam #1 (Version B) CS 122A Spring 2018

Midterm Exam #2 (Version B) CS 122A Spring 2018

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

UNIVERSITY OF CALIFORNIA College of Engineering Department of EECS, Computer Science Division

A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

Midterm Exam #2 (Version B) CS 122A Spring 2018

Midterm Exam #2 (Version C) CS 122A Spring 2018

Endterm Exam (Version B) CS 122A Spring 2017

Final Review. Zaki Malik November 20, 2008

Introduction to Data Management. Lecture #10 (Relational Calculus, Continued)

Lecture 2 SQL. Instructor: Sudeepa Roy. CompSci 516: Data Intensive Computing Systems

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

Review: Where have we been?

1 (10) 2 (8) 3 (12) 4 (14) 5 (6) Total (50)

Introduction to Data Management. Lecture #13 (Relational Calculus, Continued) It s time for another installment of...

CITS3240 Databases Mid-semester 2008

Experimenting with bags (tables and query answers with duplicate rows):

CIS 330: Applied Database Systems. ER to Relational Relational Algebra

Spring 2013 CS 122C & CS 222 Midterm Exam (and Comprehensive Exam, Part I) (Max. Points: 100)

CSE 444: Database Internals. Section 4: Query Optimizer

Introduction to Data Management. Lecture 14 (SQL: the Saga Continues...)

CSE 444: Database Internals. Sec2on 4: Query Op2mizer

Homework 3: Relational Database Design Theory (100 points)

CompSci 516: Database Systems

Basic form of SQL Queries

Relational Algebra. Study Chapter Comp 521 Files and Databases Fall

Lecture 3 SQL - 2. Today s topic. Recap: Lecture 2. Basic SQL Query. Conceptual Evaluation Strategy 9/3/17. Instructor: Sudeepa Roy

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

1. (a) Briefly explain the Database Design process. (b) Define these terms: Entity, Entity set, Attribute, Key. [7+8] FIRSTRANKER

Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601

Relational Algebra. Relational Query Languages

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

CompSci 516 Data Intensive Computing Systems

CS 461: Database Systems. Final Review. Julia Stoyanovich

This lecture. Step 1

DATABASE MANAGEMENT SYSTEMS

CIS 330: Applied Database Systems

Lecture 3 More SQL. Instructor: Sudeepa Roy. CompSci 516: Database Systems

Lecture 2 SQL. Announcements. Recap: Lecture 1. Today s topic. Semi-structured Data and XML. XML: an overview 8/30/17. Instructor: Sudeepa Roy

Principles of Data Management. Lecture #9 (Query Processing Overview)

Database Applications (15-415)

Database Systems. Course Administration. 10/13/2010 Lecture #4

CS 222/122C Fall 2016, Midterm Exam

Database Management Systems. Chapter 4. Relational Algebra. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

SQL: The Query Language Part 1. Relational Query Languages

Relational Algebra. [R&G] Chapter 4, Part A CS4320 1

CAS CS 460/660 Introduction to Database Systems. Relational Algebra 1.1

Introduction to Data Management. Lecture #14 (Relational Languages IV)

Schema Normalization. 30 th August Submitted By: Saurabh Singla Rahul Bhatnagar

Relational Algebra Homework 0 Due Tonight, 5pm! R & G, Chapter 4 Room Swap for Tuesday Discussion Section Homework 1 will be posted Tomorrow

Introduction to Data Management. Lecture #11 (Relational Algebra)

Keys, SQL, and Views CMPSCI 645

SQL: Queries, Programming, Triggers

CS 186, Fall 2002, Lecture 8 R&G, Chapter 4. Ronald Graham Elements of Ramsey Theory

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

Midterm 2: CS186, Spring 2015

CSE 444 Midterm Test

Enterprise Database Systems

Introduction to Data Management. Lecture #11 (Relational Languages I)

Draw A Relational Schema And Diagram The Functional Dependencies In The Relation >>>CLICK HERE<<<

Database Management System Prof. Partha Pratim Das Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Relational Query Languages. Relational Algebra. Preliminaries. Formal Relational Query Languages. Relational Algebra: 5 Basic Operations

SQL: Queries, Constraints, Triggers

Database Systems ( 資料庫系統 )

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

Schema And Draw The Dependency Diagram

Database Management Systems Paper Solution

Today s topics. Null Values. Nulls and Views in SQL. Standard Boolean 2-valued logic 9/5/17. 2-valued logic does not work for nulls

Relational Algebra 1

v Conceptual Design: ER model v Logical Design: ER to relational model v Querying and manipulating data

SQL. Chapter 5 FROM WHERE

Database Systems. October 12, 2011 Lecture #5. Possessed Hands (U. of Tokyo)

QUIZ 1 REVIEW SESSION DATABASE MANAGEMENT SYSTEMS

Announcements If you are enrolled to the class, but have not received the from Piazza, please send me an . Recap: Lecture 1.

Lecture #8 (Still More Relational Theory...!)

Introduction to Data Management. Lecture 16 (SQL: There s STILL More...) It s time for another installment of...

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

More Normalization Algorithms. CS157A Chris Pollett Nov. 28, 2005.

Database Applications (15-415)

MySQL Installation Guide (Windows)

Database Applications (15-415)

CSE 344 Final Examination

SQL Part 2. Kathleen Durant PhD Northeastern University CS3200 Lesson 6

Chapter 2 Introduction to Relational Models

Course No: 4411 Database Management Systems Fall 2008 Midterm exam

Database Systems. Announcement. December 13/14, 2006 Lecture #10. Assignment #4 is due next week.

CompSci 516 Database Systems. Lecture 2 SQL. Instructor: Sudeepa Roy

Database Management

Relational Algebra. Note: Slides are posted on the class website, protected by a password written on the board

Relational Query Languages

The University of British Columbia

CMU - SCS / Database Applications Spring 2013, C. Faloutsos Homework 1: E.R. + Formal Q.L. Deadline: 1:30pm on Tuesday, 2/5/2013

Overview of DB & IR. ICS 624 Spring Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa

Relational model continued. Understanding how to use the relational model. Summary of board example: with Copies as weak entity

MySQL Installation Guide (Windows)

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

CS403- Database Management Systems Solved Objective Midterm Papers For Preparation of Midterm Exam

Transcription:

NAME: SOLUTION SEAT NO.: STUDENT ID: Midterm Exam (Version B) CS 122A Spring 2017 Max. Points: 100 (Please read the instructions carefully) Instructions: - The total time for the exam is 80 minutes; be sure to budget your time accordingly. - The exam is closed book and closed notes but open cheat sheet. - Read each question first, in its entirety, and then carefully answer each part of the question. - If you don t understand something, ask one of the exam proctors for clarification. - If you still find ambiguities in a question, note the interpretation you are taking. QUESTION TOPIC POINTS SCORE 1 2 E-R to Relational Translation Relational Queries 20 20 20 20 3 E-R Design 25 25 4 Modeling Terms 5 5 5 6 Relational Operators FD Design Theory 10 10 20 20 TOTAL All 100 100

1 Question 1: E-R to Relational Translation (20 points) (20 pts) Translate the following E-R schema into an appropriate set of SQL tables. Avoid having more tables than needed, and be sure that your translated design expressed as a series of CREATE TABLE statements in SQL includes any/all appropriate (i) primary keys, (ii) unique keys, (iii) NOT NULL constraints, (iv) FOREIGN KEY constraints, and (v) ON DELETE options. CREATE TABLE Building( bldgid INTEGER, manager VARCHAR (35), address VARCHAR (60), PRIMARY KEY (bldgid) CREATE TABLE Office( bldgid INTEGER, no INTEGER, sqft INTEGER, rooms INTEGER, floor INTEGER, PRIMARY KEY (bldgid, no), FOREIGN KEY (bldgid) REFRENCES Building(bldgid) ON DELETE CASCADE CREATE TABLE Renter( rid INTEGER, name VARCHAR (35), phone VARCHAR (20), PRIMARY KEY rid CREATE TABLE Rent( rid INTEGER, bldgid INTEGER, no INTEGER, rate DECIMAL (6,2), PRIMARY KEY (rid, bldg, no), FOREIGN KEY (rid) REFERENCES Renter (rid) ON DELETE CASCADE, FOREIGN KEY (bldgid,no) REFERENCES Office (bldgid, no) ON DELETE CASCADE

2 Question 2: Relational Queries (20 points) Write each of the following queries in the indicated relational query language against the Hoofers Sailing Club schema that we ve been using in the lectures. Be sure to read each problem carefully! Sailors( sid, sname, rating, age) Reserves(sid, bid, day) Boats( bid, bname, color) (5 pts) Using the relational algebra, print the ids of boats that have been reserved by one or more sailors named Harris but no sailors named John. π bid (Reserves (σ sname = Harris (Sailors))) - π bid (Reserves (σ sname = John (Sailors))) (5 pts) Using English, state the query to which the following would be the relational calculus answer: {b b Boats ( s Sailors ( (s.age = 40) } ( r Reserves ((r.sid = s.sid) (r.bid = b.bid)))) Find the boats that have been reserved by all of the sailors whose is age = 40. (5 pts) Using the relational algebra, print the names and colors of boats that have been reserved by a sailor named Kim or by a sailor named Ghim: π bname, color((boats Reserves) (σ sname = Kim sname = Ghim (Sailors))) (5 pts) Using the relational calculus, print the names and colors of boats that have been reserved both by a sailor named Alex and by a sailor named Alexander: {t(name,color) b Boats(bname=t.name^color=t.color ^ r1 Reserves(r1.bid=b.bid ^ s1 Sailors(s1.sid=r1.sid^s.sname= Alex ))^ r2 Reserves(r2.bid=b.bid ^ s2 Sailors(s2.sid=r1.sid^s.sname= Alexander )))}

3 Question 3: E-R Design (25 points) (25 pts) You have been hired by a new startup, PhotoTweets, to help them with the data management aspects of a new online service. They plan to serve home-made photos to mobile users from a cluster of Windows servers. Your job is to design an E-R conceptual schema for their database. Draw your E-R design below, starting from the partial picture that we ve provided. Be sure to capture all relevant entities, relationships, and attributes. Clearly label each relationship to indicate its cardinality constraints (e.g., 1:1, 1:N, N:M), participation constraints (using double lines where appropriate), and roles (if needed). Mark the primary key for each entity set (by underlining it). Here s what you have been told by their lead application developer: Each member has a unique member id, a name, a unique e-mail address, and a birthdate. Members can become photo sharing friends by liking one another. (Note: Likes may not be symmetric, i.e., one member might like another member but the opposite might not hold.) Members can choose to post photos, and their postdate should be recorded. Each photo will be posted by one member, and every photo must indeed have an associated member who posted it. Photos have a unique id, a GPS location data, the date that it was taken on, a thumbnail preview, a size, and a file name. Photos also have a set of tags (e.g., scenery, people, animal ) intended to help members when searching for photos of potential interest. To avoid use of the service by social outcasts, every member must be liked by at least one other member. Some photos are ads. Ad photos also have a sponsoring company name and a product name.

4 Question 4: Modeling Terms (5 points) (5 pts) Refer again to the description of the PhotoTweets data in Question 3. Match each of the modeling constructs in the left column below with their best-matching feature (from Question 3) in the right column below. Indicate each answer by writing the letter of the relevant description feature to the left of each modeling construct. ( Hint: You should end up using each description feature once.) Modeling construct Description feature e Super key d Multivalued attribute b Atomic attribute a or c Candidate key c or a Primary key a. Member.email b. Post.postdate c. Member.id d. Photo.tags e. (Member.email, Member.name) Question 5: Relational Operators (10 points) (1 pt each) Given two relations R and S, where R has N R tuples, S has N S tuples, and N R > N S > 0, what are the minimum and maximum possible result cardinalities for the following relational algebra queries expressed in terms of N R and N S? R S: min size: N R max size: N R +N S σ attr=val ( R): min size: 0 max size: N R R S: min size: N R -N S _OR 1 max size: N R R S: min size: 0 max size: N S *N R π attr1, attr2 ( S): min size: 1 max size: N S

5 Question 6: FD Design Theory (20 points) Consider a relational table with schema R (a, b, c, d, e). Each of the sub-problems below is based on a different list of FDs for R. For each sub-problem, list the candidate keys for R based on its given FD list and indicate which is the highest normal form 1NF, 2NF, 3NF, or BCNF that R is currently in based on the given FD list. If asked (as in one case below), normalize the design into BCNF (else stop at 3NF) by decomposing R into several relations that have the lossless join and dependency-preserving properties. ( Reminder : Be sure to use parentheses wherever you are indicating a composite key.) Last and also least, answer the 1-point question at the very end as well. (5 pts) (a, b) c, d e - Candidate key(s) for R : (a,b,d) - Highest normal form: 1NF (5 pts) (a, b) e, (a, b) c, b d, d b, (a, d) c - Candidate key(s) for R : (a,b),(a,d) - Highest normal form: 3NF (7 pts) ( c, d) e, a b, b d, b c, candidate key is a. - Highest normal form: 2NF - Normalized BCNF or 3NF design: ( a,b),( b,c,d),( c,d,e) (2 pts) Suppose that R contains a tuple (95, Li, Database Concepts, CS, 2017-05-06). If c d is a functional dependency on R, give an example of another tuple that, if inserted into R, would violate this constraint. (95, Li, Database Concepts, Business,2017-05-06) (1 pt) Give the largest possible superkey for R : R( a,b,c,d,e)