Midterm Exam SOLUTION



Similar documents
Databases What the Specification Says

Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

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

Review: Participation Constraints

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

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

Database Design. Database Design I: The Entity-Relationship Model. Entity Type (con t) Chapter 4. Entity: an object that is involved in the enterprise

Data Modeling. Database Systems: The Complete Book Ch ,

Probability. Section 9. Probability. Probability of A = Number of outcomes for which A happens Total number of outcomes (sample space)

SQL Data Definition. Database Systems Lecture 5 Natasha Alechina

Answers included WORKSHEET: INTEGRITY CONTROL IN RELATIONAL DATABASES

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

Object-Based Databases

SQL Tables, Keys, Views, Indexes

SQL NULL s, Constraints, Triggers

Relational Algebra and SQL

In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

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

CSCE 156H/RAIK 184H Assignment 4 - Project Phase III Database Design

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

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

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

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

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

Chapter 6: Integrity Constraints

CS Awards in Americas

EECS 647: Introduction to Database Systems

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7

Lecture 6. SQL, Logical DB Design

IT2305 Database Systems I (Compulsory)

The SQL Query Language. Creating Relations in SQL. Referential Integrity in SQL. Basic SQL Query. Primary and Candidate Keys in SQL

Relational Databases

Exercise 1: Relational Model

types, but key declarations and constraints Similar CREATE X commands for other schema ëdrop X name" deletes the created element of beer VARCHARè20è,

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


The University of British Columbia

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

Software Requirements Specification for DLS SYSTEM

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

Database Design. Goal: specification of database schema Methodology: E-R Model is viewed as a set of

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

The Entity-Relationship Model

Going for the Gold in the Cidade Maravilhosa: Who Will Win the 2016 Olympic Games in Rio de Janeiro?

CSC 443 Data Base Management Systems. Basic SQL

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

IT2304: Database Systems 1 (DBS 1)

Conceptual Design Using the Entity-Relationship (ER) Model

Is winning medals in international sport simply a matter of money?

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

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

Relational Database Concepts

City University of Hong Kong. Information on a Course offered by Department of Computer Science with effect from Semester A in 2014 / 2015

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

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

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

The core theory of relational databases. Bibliography

Database Management Systems,

Statistics E100 Fall 2013 Practice Midterm I - A Solutions

Schema Design and Normal Forms Sid Name Level Rating Wage Hours

The Relational Data Model: Structure

Database Design and the E-R Model

CS411 Database Systems

Rio 2016 Olympic Games Rule 40 Guidelines

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Part I: Entity Relationship Diagrams and SQL (40/100 Pt.)

COMP 378 Database Systems Notes for Chapter 7 of Database System Concepts Database Design and the Entity-Relationship Model

COUNTING SUBSETS OF A SET: COMBINATIONS

CSC 443 Fall 2011 Dr. R. M. Siegfried. Answers to Assignment #1

Measures of Central Tendency: Mean, Median, and Mode Examples

3. Relational Model and Relational Algebra

Database Design Process. Databases - Entity-Relationship Modelling. Requirements Analysis. Database Design

Mind on Statistics. Chapter 4

Number of hours in the semester L Ex. Lab. Projects SEMESTER I 1. Economy Philosophy Mathematical Analysis Exam

Review Entity-Relationship Diagrams and the Relational Model. Data Models. Review. Why Study the Relational Model? Steps in Database Design

Version A Page The diagram shows two bowling balls, A and B, each having a mass of 7.00 kilograms, placed 2.00 meters apart.

MAJOR EVENTS COORDINATION UNIT

New York University Computer Science Department Courant Institute of Mathematical Sciences

How To Create A Table In Sql (Ahem)

SQL: Queries, Programming, Triggers

Elite Athletes, National Identity and the Olympic Games:

Using SQL Server Management Studio

A probability experiment is a chance process that leads to well-defined outcomes. 3) What is the difference between an outcome and an event?

CMPT 354 Database Systems. Simon Fraser University Summer Instructor: Oliver Schulte

The Old Orchard Swim Club

Schema Refinement and Normalization

IntroductiontoOBS. March 2013

THE OPEN UNIVERSITY OF TANZANIA FACULTY OF SCIENCE TECHNOLOGY AND ENVIRONMENTAL STUDIES BACHELOR OF SIENCE IN DATA MANAGEMENT

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

23 rd ANNUAL CHALLENGE CUP TOURNAMENT

Chapter 8. SQL-99: SchemaDefinition, Constraints, and Queries and Views

Example Instances. SQL: Queries, Programming, Triggers. Conceptual Evaluation Strategy. Basic SQL Query. A Note on Range Variables

The Category Management Knowledge Group Presents...

Centennial Gala.

Transcription:

CS 461, Database Systems Name: Midterm Exam SOLUTION Drexel email: 1 25 2 25 3 30 Total 80 I certify that this exam is entirely my own work. Signature Date Instructions: This is an open book, open notes exam. Use of electronic devices is not permitted. You have 1 hour to answer all questions. Show your work when appropriate. Good luck! 1

Problem 1 (25 points) Business rules to ER diagrams (a) (10 points) Consider the business rules below that describe a database of books and authors. Draw an ER diagram that encodes these business rules. Clearly mark all key and participation constraints. An author is described by a name and a date of birth (dob). No two authors have the same combination of name and dob. A book is described by an ISBN, a title and a year when it was written (year). No two books have the same ISBN number. A book is written by exactly one author. An author is only included in the database is she has authored at least one book. There is participation on AUTHORS (bold line), and key and participation on BOOKS (arrowhead, bold line). (b) (15 points) Consider the business rules below that describe a database of scientists, discoveries and awards. Draw an ER diagram that encodes these business rules. Clearly mark all key and participation constraints. A scientist is described by a name, a field of study, and a date of birth (dob). No two scientists have the same combination of name and dob. A discovery has a name. No two discoveries have the same name. An award has a name, which uniquely identifies it. Scientists make discoveries. A discovery is made by one or several scientists. A scientist who made no discoveries is not tracked in our database. Scientists receive awards. A scientist may receive the same award more than once in different years. All years in which a scientist received a particular award must be recorded. There is participation on SCIENTISTS and DISCOVERIES w.r.t. make (bold lines). 2

Problem 2 (25 points) ER diagrams to SQL Do not create cycles when you establish foreign keys, i.e., you should not have a foreign key from table A to table B and also a foreign key from table B to table A in your implementation. (a) (15 points) Consider an ER diagram below. Write SQL statements (create table) that implement the constraints specified by this ER diagram. Create as many tables as is required. Briefly explain which constraints are captured in your relational implementation, and in what way. If a constraint cannot be implemented, state that explicitly in your description. You will not receive full credit without a proper description. The line from CHEFS to work_at is bold and has an arrowhead. The line CHEFS to own is not bold and has an arrowhead. The lines from RESTAURANTS to own and work_at are not bold and do not have arrowheads. create table Restaurants ( name varchar(64), city varchar(64), primary key (name, city) create table Chefs ( ssn char(9) primary key, name varchar(64), work_at_name varchar(64) not null, work_at_city varchar(64) not null, own_name varchar(64), own_city varchar(64), foreign key (works_at_name, works_at_city) references Restaurants (name, city), foreign key (owns_name, owns_city) references Restaurants (name, city) This implementation captures all constraints. Both key constraints on CHEFS are captured by representing the entity set CHEFS and the two relationship sets 3

in the same table with foreign keys (i.e., there is only one tuple per chef in this table, hence a chef cannot be associated with more than one restaurant through either ownership or work). Participation on CHEFS in work_at is represented by making work_at_name and work_at_city not null. (b) (10 points) Consider an ER diagram below. Write SQL statements (create table) that implement the constraints specified by this ER diagram. Create as many tables as is required. Briefly explain which constraints are captured in your relational implementation, and in what way. If a constraint cannot be implemented, state that explicitly in your description. You will not receive full credit without a proper description. The line from SATELLITE to orbits is bold and has an arrowhead; the line from PLANET to orbits is not bold and has an arrowhead. Option 1: create table Satellites_Orbit_Planets ( sat_name varchar(64) unique, sat_mass integer, planet_name varchar(64) primary key, planet_mass integer This implementation captures all constraints. Key constraints on both entity sets are captured because there is only 1 tuple in this relation per planet (because planet_name is the primary key) and per satellite (because sat_name is unique). Participation on Satellites is enforced because there cannot be a tuple in this relation in which sat_name is specified by planet_name is not (since planet_name is not null). Note that there is no participation on planets, which is correct. A planet without a satellite can exist in our database, for this planet the value of sat_name will be null. A shortcoming of this implementation is that there is an opportunity to specify sat_mass without specifying sat_name. However, this is subtle and this solution is acceptable for full credit. Option 2: 4

create table Planets ( name varchar(64) primary key, mass integer create table Satellites_Orbit_Planets ( name varchar(64) primary key, mass integer, planet_name varchar(64) not null unique, foreign key (planet_name) references Planets(name) This implementation captures all constraints. Key and participation on SATELLITES is captured by representing both the entity set SATELLITES and the relationship set in the table Satellite, with satellite name as the primary key. Key constraint on PLANETS is represented by making planet_name unique in Satellites. This way a particular planet participated in the relationship set at most once. Note that this solution does not suffer from the shortcoming of the implementation in Option 1. 5

Problem 3 (30 points) Relational algebra and SQL Olympics (year, host, kind) Medals (country, sport, year, event, medal) Olympics (year, host, kind) year host kind 2012 UK Summer 2010 Canada Winter 2008 China Summer 2006 Italy Winter 2004 Greece Summer 2002 USA Winter Medals (country, sport, year, event, medal) country sport *year event medal USA swimming 2012 100m freestyle gold USA swimming 2012 100m butterfly gold USA swimming 2012 200m butterfly silver Canada figure skating 2010 ice dancing gold Canada figure skating 2010 ladies singles bronze China figure skating 2010 pair skating gold China swimming 2008 400m freestyle silver USA swimming 2008 200m freestyle gold Brazil swimming 2008 50m freestlyle gold USA figure skating 2002 men s singles bronze USA figure skating 2002 ladies singles gold China figure skating 2002 pair skating bronze Russia figure skating 2002 men s singles gold Russia figure skating 2002 ladies singles silver 6

(a) (10 points) Write a SQL query that lists years in which the host country won a gold medal and a silver medal at an Olympic event. select o.year from Medals m1, Medals m2, Olympics o where m1.year = o.year and m1.country = o.host and m1.medal = 'gold' and m2.year = o.year and m2.country = o.host and m2.medal = 'silver' (b) (10 points) Write two equivalent relational algebra expressions that list sports in which the US won a medal in a Summer Olympics. Any two of these are sufficient, other solutions are also possible. π sport ((σ country='usa' Medals) >< (σ kind='summer' Olympics)) π sport (σ country='usa' (Medals >< (σ kind='summer' Olympics)) π sport (σ country='usa' kind='summer' (Medals >< Olympics)) (c) (10 points) Write a SQL query and an equivalent relational algebra expression that lists names of countries that won a medal at a Summer Olympics but that never won a medal at a Winter Olympics. List each country name only once. select distinct m.country from Medals m, Olympics o where m.year = o.year and o.kind = 'Summer' EXCEPT select m.country from Medals m, Olympics o where m.year = o.year and o.kind = 'Winter' Note that distinct is only necessary in the first part of the query. But if it s there in both parts, the query is correct and received full credit. There are several ways to write the relational algebra expression, one option is below. π country ((σ kind='summer' Olympics) >< Medals) π country ((σ kind='w int er' Olympics) >< Medals) 7