CMPT 354 Assignment 1 Key 2000-1 Instructor: G. Louie



Similar documents
Assignment 3: SQL Queries. Questions 1. The following relations keep track of airline flight information:

SQL: QUERIES, CONSTRAINTS, TRIGGERS

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

DATABASE MANAGEMENT SYSTEMS SOLUTIONS MANUAL. Raghu Ramakrishnan et al. University of Wisconsin Madison, WI, USA

CIS 631 Database Management Systems Sample Final Exam

Exercise 1: Relational Model

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

Database Design Process

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

We know how to query a database using SQL. A set of tables and their schemas are given Data are properly loaded

DATABASE MANAGEMENT SYSTEMS SOLUTIONS MANUAL. Raghu Ramakrishnan et al. University of Wisconsin Madison, WI, USA

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

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

The University of British Columbia

A Little Set Theory (Never Hurt Anybody)

XV. The Entity-Relationship Model

not necessarily strictly sequential feedback loops exist, i.e. may need to revisit earlier stages during a later stage

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

DATABASE DESIGN. - Developing database and information systems is performed using a development lifecycle, which consists of a series of steps.

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

Database Design Process

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

Relational Databases

The Entity-Relationship Model

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

The Entity-Relationship Model

DATABASE MANAGEMENT SYSTEMS SOLUTIONS MANUAL THIRD EDITION

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

Introduction to Database Systems CS4320/CS5320. CS4320/4321: Introduction to Database Systems. CS4320/4321: Introduction to Database Systems

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

The Mathematics 11 Competency Test Percent Increase or Decrease

Fundamentals of Database System


The Graphical Method: An Example

Elena Baralis, Silvia Chiusano Politecnico di Torino. Pag. 1. Physical Design. Phases of database design. Physical design: Inputs.

6.2 Permutations continued

Chapter 5: Logical Database Design and the Relational Model Part 2: Normalization. Introduction to Normalization. Normal Forms.

Microeconomics Instructor Miller Practice Problems Labor Market

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

Answers included WORKSHEET: INTEGRITY CONTROL IN RELATIONAL DATABASES

Chapter 6: Integrity Constraints

CHAPTER 3: DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL

ER modelling, Weak Entities, Class Hierarchies, Aggregation

x 2 + y 2 = 1 y 1 = x 2 + 2x y = x 2 + 2x + 1

Unified Lecture # 4 Vectors

2013 MBA Jump Start Program

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

Week 1: Functions and Equations

Limitations of E-R Designs. Relational Normalization Theory. Redundancy and Other Problems. Redundancy. Anomalies. Example

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

Data exchange. L. Libkin 1 Data Integration and Exchange

Data Modeling. Database Systems: The Complete Book Ch ,

Objectives of SQL. Terminology for Relational Model. Introduction to SQL

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

7 Literal Equations and

Functions. MATH 160, Precalculus. J. Robert Buchanan. Fall Department of Mathematics. J. Robert Buchanan Functions

SAMPLE FINAL EXAMINATION SPRING SESSION 2015

Vocabulary Words and Definitions for Algebra

Introduction to tuple calculus Tore Risch

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

Relational Algebra and SQL

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Chapter 3 Consumer Behavior

Test1. Due Friday, March 13, 2015.

Maths Workshop for Parents 2. Fractions and Algebra

Geometric Optics Converging Lenses and Mirrors Physics Lab IV

Summer Assignment for incoming Fairhope Middle School 7 th grade Advanced Math Students

Scheme G. Sample Test Paper-I

Engineering Economics: Comparing Financial Characteristics of Design Options

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

Solutions of Equations in Two Variables

Chapter 2: Entity-Relationship Model. Entity Sets. " Example: specific person, company, event, plant

Relational Algebra. Basic Operations Algebra of Bags

Answer Key for California State Standards: Algebra I

= δx x + δy y. df ds = dx. ds y + xdy ds. Now multiply by ds to get the form of the equation in terms of differentials: df = y dx + x dy.

Section 1.3 P 1 = 1 2. = P n = 1 P 3 = Continuing in this fashion, it should seem reasonable that, for any n = 1, 2, 3,..., =

1 Error in Euler s Method

THE AMERICAN AIRLINEW INDUSTRY AND SOUTHWEST AIRLINES. low profit margins. Within the industry, however, there have been differences in terms of

2. Exercising the option - buying or selling asset by using option. 3. Strike (or exercise) price - price at which asset may be bought or sold

Angles and Quadrants. Angle Relationships and Degree Measurement. Chapter 7: Trigonometry

Student Outcomes. Lesson Notes. Classwork. Exercises 1 3 (4 minutes)

4 G: Identify, analyze, and synthesize relevant external resources to pose or solve problems. 4 D: Interpret results in the context of a situation.

AN EXPLANATION OF JOINT DIAGRAMS

Chapter 4. Probability and Probability Distributions

Lecture 10: What is a Function, definition, piecewise defined functions, difference quotient, domain of a function

Entity - Relationship Modelling

Capital Budgeting Formula

CSC340S - Information Systems Analysis and Design

1 Structured Query Language: Again. 2 Joining Tables

Review of Fundamental Mathematics

IT2304: Database Systems 1 (DBS 1)

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

Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations

Handout #1: Mathematical Reasoning

Schema Design and Normal Forms Sid Name Level Rating Wage Hours

Transcription:

Total marks: 75 Due: Feb 2, 2000 by 20:30 CMPT 354 Assignment 1 Key 2000-1 Instructor: G. Louie 1. (4 marks) Explain the difference between logical and physical data independence. Logical data independence means that users are shielded from changes in the logical structure of the data (2 marks), while physical data independence insulates users from changes in the physical storage of the data (2 marks). 2. Given the relations shown below, show the results of the following relational operations: S P J S# city P# city J# City S1 Paris P1 Paris J1 Paris S2 Berne P2 Berne J2 Rome S3 Oslo P3 Rome J3 Oslo S4.null. P4.null. J4.null. S5 Paris P5.null. J5 Rome a) (2 marks) The projection of S on city b) (2 marks) The union of result (a) and the projection of P on city c) (2 marks) The set difference of result (a) and the projection of P on city (in that order) d) (2 marks) The intersection of result (c) and the projection of J on city e) (3 marks) The product of P and J f) (3 marks) The natural join of P and J g) (4 marks) The outer natural join of S and P. (a) (b) (c) (d) city city City City Paris Paris Oslo Oslo Berne Berne Oslo Oslo Rome Assignment 1 CMPT 354 Page 1 of 8

(e) (f) (g) P# P_city J# J_city P# city J# S# city P# P1 Paris J1 Paris P1 Paris J1 S1 Paris P1 P2 Berne J1 Paris P3 Rome J2 S2 Berne P2 P3 Rome J1 Paris P3 Rome J5 S3 Oslo.null. P4.null. J1 Paris S5 Paris P1 P5.null. J1 Paris.null. Rome P3 P1 Paris J2 Rome P2 Berne J2 Rome P3 Rome J2 Rome P4.null. J2 Rome P5.null. J2 Rome P1 Paris J3 Oslo P2 Berne J3 Oslo P3 Rome J3 Oslo P4.null. J3 Oslo P5.null. J3 Oslo P1 Paris J4.null. P2 Berne J4.null. P3 Rome J4.null. P4.null. J4.null. P5.null. J4.null. P1 Paris J5 Rome P2 Berne J5 Rome P3 Rome J5 Rome P4.null. J5 Rome P5.null. J5 Rome 3. Suppose you are given the following information about a database for a chain of drug stores: a drugstore sells drugs prescribed by doctors to patients, each drugstore in the chain is identified by a store name, address, and a phone number, patients are identified by a patient id, and their names, addresses, and ages must be recorded, Assignment 1 CMPT 354 Page 2 of 8

doctors are identified by a doctor id. Each doctor s name, specialty, and years of experience must be recorded, each drug is made by a pharmaceutical company and sold to the drugstore. The drug s trade name identifies the drug uniquely from among the products of that company. For each drug, the trade name and formula must be recorded each pharmaceutical company is identified by name and has a phone number, every patient has a primary doctor, every doctor has at least one patient, each drugstore sells several drugs and has a price for each. A drug could be sold at several drugstores, and the price could vary from one drugstore to another, doctors prescribe drugs for patients. A doctor could prescribe one or more drugs for several patients, and a patient could obtain prescriptions from several doctors, each prescription has a date and a quantity associated with it. You can assume that if a doctor prescribes the same drug for the same patient more than once, only the last such prescription needs to be stored, pharmaceutical companies have long-term contracts with drugstores. A pharmaceutical company can contract with several drugstores, and a drugstore can contract with several pharmaceutical companies. For each contract, you have to store a start date, an end date, and the text of the contract, drugstores appoint a supervisor for each contract. There must always be a supervisor for each contract, but the contract supervisor can change over the lifetime of the contract, if a pharmaceutical company is deleted, you need not keep track of its products any longer. a) (8 marks) Draw an ER diagram that captures the above information and identify any constraints that are not captured by the diagram. Here is a sample ER diagram. Depending on the assumptions made (which should be clearly stated), other diagrams are possible! Start w. 8 marks and deduct one for each missing entity, attribute, role indicator, cardinality indicator, etc. Note that the attribute names do not have to match exactly. Note that the entity drug is a weak entity set and the relationship set make is also weak, as indicated by the thicker lines in this diagram as opposed to the double lines used in the textbook. Assignment 1 CMPT 354 Page 3 of 8

b) (8 marks) Define the relational schema corresponding to the entity sets and relationship sets. Underline the primary keys. drugstore(name, address, phone_num) doctor(doc_id, name, specialty, exp_years) patient(p_id, name, address, age) pri_physician(p_id, doc_id) prescription(p_id, doc_id, date, quantity, trade_name, pharm_name) drug(pharm_name, trade_name, formula) sell(store_name, pharm_name, trade_name, price) contract(store_name, pharm_name, start_date, end_date, text, supervisor) Assignment 1 CMPT 354 Page 4 of 8

4. Suppose you are given the following schema: employee(emp_id, name, salary) flights(flight_no, from, to, distance, depart_time, arrival_time) aircraft(aircraft_id, manufacturer, model, range) certified(emp_id, aircraft_id) The certified relation indicates which employee(s) is/are certified to fly which aircraft. For each of the following queries, give an expression in i) the relational algebra, ii) the tuple relational calculus, iii) the domain relational calculus. For example, the following expressions would be used to find the names of employees who are certified to fly aircraft manufactured by Boeing : i) Π name (σ manufacturer = 'Boeing' (aircraft certified employee)) ii) {t e employee c certified a aircraft (t[name] = e[name] a[aircraft_id] = c[aircraft_id] e[emp_id] = c[emp_id] a[manufacturer] = "Boeing")} iii) {<n> a, e, m ( <a, e> certified <e, n> employee <a, m> aircraft m = "Boeing")} a) (3 marks) Find the flight numbers of all the flights originating from Vancouver which depart after 13:00. i) Π flight_no (σ from = 'Vancouver' depart_time > '13:00' (flights)) ii) {t f flights (t[flight_no] = f[flight_no] f[from] = Vancouver f[depart_time] > "13:00")} iii) {<fn> fr, d ( <fn, fr, d> flights fr = "Vancouver" d > "13:00")} Assignment 1 CMPT 354 Page 5 of 8

b) (6 marks) Find the employee id s of the pilots certified to fly aircraft manufactured by Boeing. i) Π emp_id (σ manufacturer = 'Boeing' (aircraft certified)) ii) {t c certified a aircraft (t[emp_id] = c[emp_id] a[aircraft_id] = c[aircraft_id] a[manufacturer] = "Boeing")} iii) {<e> a, m ( <a, e> certified <a, m> aircraft m = "Boeing")} c) (6 marks) Find the aircraft_ids of all aircraft that can be used on non-stop flights (i.e. where the aircraft.range > flights.distance) from Vancouver to Tokyo. i) Π aircraft_id (σ range > distance (aircraft (σ from = 'Vancouver' to = 'Tokyo' (flights)))) ii) {t a aircraft f flights (t[aircraft_id] = a[aircraft_id] f[from] = "Vancouver" f[to] = "Tokyo") a[range] > f[distance]} iii) {<a> r, f, t, d ( <a, r> aircraft <f, t, d> flights f = "Vancouver" t = "Tokyo" r > d)} d) (6 marks) Identify the flight numbers that can be piloted by every pilot whose salary is more than $100,000. Note: the key is to realize that only those flights with distances less than a given aircraft s range and the given aircraft are certified with pilots earning more than $100,000 can meet the requirements of the query. i) Π flight_no (σ range > distance salary > 100,000 (aircraft flights certified employee)) ii) {t e employee f flights c certified a aircraft (t[flight_no] = f[flight_no] a[range] > f[distance] e[salary] > 100,000 a[aircraft_id] = c[aircraft_id] e[emp_id] = c[emp_id])} iii) {<f> e, a, r, d, s ( <e, a> certified <a, r> aircraft <f, d> flights <e, s> employee s > 100,000 r > d)} Assignment 1 CMPT 354 Page 6 of 8

e) (6 marks) Find the names of pilots who can operate planes with a range greater than 3,000 miles but are not certified on any aircraft manufactured by Boeing. i) Π name (employee (Π emp_id (σ range > 3000 (aircraft certified)) Π emp_id (σ manufacturer = Boeing (aircraft certified)))) ii) {t e employee c certified ( a aircraft (t[name] = e[name] a[aircraft_id] = c[aircraft_id] e[emp_id] = c[emp_id] a[range] > 3000)) ( c2 certified ( a2 aircraft (a2[manufacturer] = Boeing a2[aircraft_id] = c2[aircraft_id] e[emp_id] = c2[emp_id])))} iii) {<n> e, a, r, a2, m ( <e, a> certified <a, r> aircraft <e, n > employee r > 3000 (<e, a2> certified <a2, m> aircraft m = Boeing ))} f) (6 marks) Find the employee id s of the employees who make the highest salary. Note: first find all the employees who do not have the highest salary and subtract these from the original list of all employees. The remaining employees will have the highest salary. i) Π emp_id (employee) (Π e2.emp_id (employee employee.salary > e2.salary ρ e2 (employee))) ii) {t e1 employee (t[emp_id] = e2[emp_id] ( e2 employee (e2[salary] > e1[salary]))} iii) {<e1> e2,s1, s2 ( <e1, s1> employees (<e2, s2> employees s2 > s1)} Assignment 1 CMPT 354 Page 7 of 8

5. (4 marks) What is an unsafe query? Give an example and explain why it is important to disallow such queries. An unsafe query is a query in relational calculus which returns an infinite number of results. It is important to disallow such queries because a database needs to return results for a query after a finite amount of time. An example of an unsafe query is: { e (e employees)} This query returns all objects which are not employees. The results of this query is infinite and thus the query is unsafe. (2 marks for definition/explanation, 2 marks for a reasonable example). Assignment 1 CMPT 354 Page 8 of 8