Summer 2009 CSCC43: Introduction to Databases s. Midterm Test



Similar documents
University of Massachusetts Amherst Department of Computer Science Prof. Yanlei Diao

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

The University of British Columbia

Relational Algebra. Basic Operations Algebra of Bags

CSE 530A Database Management Systems. Introduction. Washington University Fall 2013

LiTH, Tekniska högskolan vid Linköpings universitet 1(7) IDA, Institutionen för datavetenskap Juha Takkinen

Relational Databases

Relational Algebra. Module 3, Lecture 1. Database Management Systems, R. Ramakrishnan 1

Relational model. Relational model - practice. Relational Database Definitions 9/27/11. Relational model. Relational Database: Terminology

Intermediate SQL C H A P T E R4. Practice Exercises. 4.1 Write the following queries in SQL:

CS 377 Database Systems. Database Design Theory and Normalization. Li Xiong Department of Mathematics and Computer Science Emory University

Graham Kemp (telephone , room 6475 EDIT) The examiner will visit the exam room at 15:00 and 17:00.

Exercise 1: Relational Model

SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

3. Relational Model and Relational Algebra

Relational Algebra 2. Chapter 5.2 V3.0. Napier University Dr Gordon Russell

Relational Algebra and SQL

Data Structure: Relational Model. Programming Interface: JDBC/ODBC. SQL Queries: The Basic From

DBMS Questions. 3.) For which two constraints are indexes created when the constraint is added?

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

Relational Algebra. Query Languages Review. Operators. Select (σ), Project (π), Union ( ), Difference (-), Join: Natural (*) and Theta ( )

COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries

Evaluation of Expressions

Converting E-R Diagrams to Relational Model. Winter Lecture 17

Quiz 2: Database Systems I Instructor: Hassan Khosravi Spring 2012 CMPT 354

The Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3

Introduction to Databases

Midterm Exam SOLUTION

4. SQL. Contents. Example Database. CUSTOMERS(FName, LName, CAddress, Account) PRODUCTS(Prodname, Category) SUPPLIERS(SName, SAddress, Chain)

Chapter 6: Integrity Constraints

The Structured Query Language. De facto standard used to interact with relational DB management systems Two major branches

Chapter 5: Overview of Query Processing

The first time through running an Ad Hoc query or Stored Procedure, SQL Server will go through each of the following steps.

Databases. DSIC. Academic Year

Chapter 13: Query Optimization

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

Databasesystemer, forår 2005 IT Universitetet i København. Forelæsning 3: Business rules, constraints & triggers. 3. marts 2005

SQL Query Evaluation. Winter Lecture 23

Execution Strategies for SQL Subqueries

Schema Mappings and Data Exchange

The Relational Algebra

MapReduce examples. CSE 344 section 8 worksheet. May 19, 2011

EECS 647: Introduction to Database Systems

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

Chapter 1: Introduction

Test1. Due Friday, March 13, 2015.

Databases What the Specification Says

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

Elena Baralis, Silvia Chiusano Politecnico di Torino. Pag. 1. Query optimization. DBMS Architecture. Query optimizer. Query optimizer.

>

CSC 443 Data Base Management Systems. Basic SQL

The Relational Data Model and Relational Database Constraints

IT2304: Database Systems 1 (DBS 1)


The Relational Data Model: Structure

IT2305 Database Systems I (Compulsory)

SQL: Queries, Programming, Triggers

Query Optimization for Distributed Database Systems Robert Taylor Candidate Number : Hertford College Supervisor: Dr.

Translating SQL into the Relational Algebra

Announcements. SQL is hot! Facebook. Goal. Database Design Process. IT420: Database Management and Organization. Normalization (Chapter 3)

Chapter 1: Introduction. Database Management System (DBMS) University Database Example

BCA. Database Management System

Transactions and the Internet

Data Integration and Exchange. L. Libkin 1 Data Integration and Exchange

Relational Division and SQL

Introduction to SQL C H A P T E R3. Exercises

SUBQUERIES AND VIEWS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 6

1 Structured Query Language: Again. 2 Joining Tables

Query Processing. Q Query Plan. Example: Select B,D From R,S Where R.A = c S.E = 2 R.C=S.C. Himanshu Gupta CSE 532 Query Proc. 1

Design of Relational Database Schemas

Θεµελίωση Βάσεων εδοµένων

Relational Calculus. Module 3, Lecture 2. Database Management Systems, R. Ramakrishnan 1

Data exchange. L. Libkin 1 Data Integration and Exchange

1.204 Lecture 3. SQL: Basics, Joins SQL

Relational Database: Additional Operations on Relations; SQL

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)

Math Released Set Algebra 1 PBA Item #13 Two Real Numbers Defined M44105

A Little Set Theory (Never Hurt Anybody)

USING MYWEBSQL FIGURE 1: FIRST AUTHENTICATION LAYER (ENTER YOUR REGULAR SIMMONS USERNAME AND PASSWORD)

Exercises. a. Find the total number of people who owned cars that were involved in accidents

Applying Constraint Logic Programming to SQL Test Case Generation

CSE 132A. Database Systems Principles

There are five fields or columns, with names and types as shown above.


Figure 4.12.Insurancedatabase.

Comp 5311 Database Management Systems. 3. Structured Query Language 1

Simple SQL Queries (3)

Database Design Final Project

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Chapter 14: Query Optimization

Database Query 1: SQL Basics

Question 1. Relational Data Model [17 marks] Question 2. SQL and Relational Algebra [31 marks]

Introduction to SQL ( )

Web-Based Database Applications ITP 300x (3 Units)

CIS 631 Database Management Systems Sample Final Exam

Solution to the Assignment 2

Course: CSC 222 Database Design and Management I (3 credits Compulsory)

Transcription:

Summer 2009 CSCC43: Introduction to Databases s Midterm Test This is a closed book test. You have 90 minutes to complete your answers, worth a total of 200 points, and 20% of your final mark. For problems 3-4, if you do not know the answer to a question, write I do not know, and you will be given 20% of the grade. If it is clear that you do not know how to answer a question but you attempt to answer it anyway, you will be given 0%. Good luck! Last Name First Name Student Number Question 1. /45 Question 2. /60 Question 3. /55 Question 4. /40 TOTAL /200-1 -

Question 1 [Short Answers 45 points]. Consider the following relation schemas R(A,B) T(B,C) and their instances r(a,b) = {<a,b>,<a,c>,<c,d>,<b,e>} t(b,c) = {<b,e>,<d,h>,<b,f>,<a,d>,<a,e>} (1.a) [10 points] Compute the result of the following relational algebra expression: π A,C (r LEFT t) A C a e a f c h a NULL b NULL (1.b) [15 points] Express r LEFT t in (1.a) using only the primary relational algebra operators (,,, ρ, σ, π, ) according to the definition of LEFT. r LEFT t = (r t) ((r - π A,B (r t)) {(NULL)}) - 2 -

(1.c) [10 points] Compute the result of the following SQL query: A SELECT R.A, COUNT(T.C) AS C_COUNT FROM R, T WHERE R.A = T.B GROUP BY R.A; C_COUNT a 4 b 2 (1.d) [10 points] Compute the result of the following SQL query: SELECT T.B, COUNT(T.C) AS C_COUNT FROM T GROUP BY T.B HAVING COUNT(T.C) > 1 S.B C_COUNT b 2 a 2-3 -

Question 2 [Relational Algebra 60 points]. Consider the following database schema computer products: Computer(maker,model,category) Model(num,speed,ram,hd,price) Maker(name,address,phone) Where maker indicates the manufacturer of the computer category takes values such as desktop, laptop, server ; Following inclusion dependencies hold o maker name o model num Express following queries in relational algebra: (2.a) [10 points] Find all the makers who make some laptop(s) π maker (σ category= laptop (Computer)) (2.b) [15 points] Find all the makers who make at lease three different desktop models π maker (σ model1 model2 model2 model3 model3 model1 (ρ model1 model (σ category= desktop (Computer)) ρ model2 model (σ category= desktop (Computer)) ρ model3 model (σ category= desktop (Computer)))) - 4 -

(2.c) [10 points] Find the phone numbers of all the makers who make desktops with speed = 3.2 π maker σ model =num (σ category = desktop (Computer) σ speed = 3.2 (Model)) (2.d) [10 points] Find the makers who don t make any desktop, and do make some laptop(s) (Computer σ category= desktop (Computer))) π maker (σ category= laptop (Computer) (2.e) [15 points] Find the makers who make all models with speed faster than 3.2 π maker, model (Computer) / (ρ model num π num (σ speed>3.2 (Model)) - 5 -

Question 3 [SQL 40 points]. Given the schema in Question 3, express following queries in SQL: (3.a) [15 points] Find all laptop models and their makers SELECT FROM WHERE maker, model Computer category = laptop (3.b) [20 points] Find all makers who make the most expensive server SELECT FROM WHERE C.maker Computer C, Model M C.category = server AND C.model = M.num AND M.price = (SELECT MAX(price) FROM Model) (3.c) [20 points] Find all desktop models with the highest speed/price ratio, and return them along with their makers SELECT FROM WHERE C.maker, C.model Computer C, Model M C.model = M.num AND M.speed/M.price ALL (SELECT (speed/price) FROM Model ) - 6 -

Question 5 [True/False questions 40 points]. For each of the following statements, indicate whether they are true of false. A correct answer is worth 5 points, no answer is worth 0 points, wrong answer is worth -3 points. The minimum you can receive on this question is 0/40. (4.a) T In SQL DDL, there can be zero or one primary key declarations in each create table statement; (4.b) F Atomicity means that each database transaction executes as if there are no other transactions running; (4.c) F A relation with 5 attributes can have more than 100 keys and superkeys; (4.d) F In SQL, relations are sets of tuples and can t have any duplicates; (4.e) T In SQL, views can be updated just like database relations; (4.f) F S R = S R, if S and R don t share any attributes, and S R = S R, if S and R have the same attributes. (4.g) F Consider relations R(A,B) and S(B,C). If B is a primary key for S, then R S may contain more tuples than R does. R S has, at most, the cardinality of R, since each tuple in R shares its B value with at most one tuple in S (since B is a primary key for S). (4.h) F Projection operators commute. That is, πx (πy (R)) = πy (πx (R)), holds for every relation R and all sets of attributes X and Y - 7 -