PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Similar documents
PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Student Number: Please fill out the identification section above as well as the one on the back page, and read the instructions below. Good Luck!

[18 marks] Consider the following schema for tracking customers ratings of books for a bookstore website.

[12 marks] Consider the following schema for a program that pairs students with mentors who offer career advice.

CS145 Midterm Examination

A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

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

CS145 Midterm Examination

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

PLEASE HAND IN. Good Luck! UNIVERSITY OF TORONTO Faculty of Arts and Science. December 2009 Examinations. CSC 343H1F Duration 3 hours.

LAB 3 Notes. Codd proposed the relational model in 70 Main advantage of Relational Model : Simple representation (relationstables(row,

Database Management Systems Paper Solution

Introduction to Data Management. Lecture #5 Relational Model (Cont.) & E-Rà Relational Mapping

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

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

McGill April 2009 Final Examination Database Systems COMP 421

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

SQL: Data Manipulation Language. csc343, Introduction to Databases Diane Horton Winter 2017

The University of British Columbia

Data about data is database Select correct option: True False Partially True None of the Above

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

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

Midterm 2: CS186, Spring 2015

SQL: Data Definition Language. csc343, Introduction to Databases Diane Horton Fall 2017

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

SQL: csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Sina Meraji. Winter 2018

UNIVERSITY OF TORONTO MIDTERM TEST SUMMER 2017 CSC343H Introduction to Databases Instructor Tamanna Chhabra Duration 120 min No aids allowed

CSE 344 Final Examination

CS145 Midterm Examination

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

Solutions. Updated of 7

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

EECS-3421a: Test #1 Design

The Semi-Structured Data Model. csc343, Introduction to Databases Diane Horton originally based on slides by Jeff Ullman Fall 2017

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

Computer Science 304

3 February 2011 CSE-3421M Test #1 p. 1 of 14. CSE-3421M Test #1. Design

Examination examples

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CSE 444, Winter 2011, Midterm Examination 9 February 2011

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

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

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

CS425 Midterm Exam Summer C 2012

QUIZ 1 REVIEW SESSION DATABASE MANAGEMENT SYSTEMS

CSEN 501 CSEN501 - Databases I

CSE 344 Midterm Exam

8) A top-to-bottom relationship among the items in a database is established by a

EXAMINATIONS 2013 MID-YEAR SWEN 432 ADVANCED DATABASE DESIGN AND IMPLEMENTATION

CPS 216 Spring 2003 Homework #1 Assigned: Wednesday, January 22 Due: Monday, February 10

CS x265 Exam 3 Spring ALL questions 5 points, except question 11 I will not use a source other than my brain on this exam: (please sign)

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

Introduction to Data Management. Lecture #4 (E-R Relational Translation)

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

CSE 344 Midterm. Wednesday, February 19, 2014, 14:30-15:20. Question Points Score Total: 100

BIRKBECK (University of London)

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

VIEW OTHER QUESTION PAPERS

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

Mahathma Gandhi University

CS 186 Midterm, Spring 2003 Page 1

Relational Database Design (II)

Good Luck! CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none. Student Number:

Northern India Engineering College, New Delhi Question Bank Database Management System. B. Tech. Mechanical & Automation Engineering V Semester

The University of British Columbia Computer Science 304 Practice Final Examination

Database Applications (15-415)

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

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

CS2300: File Structures and Introduction to Database Systems

The Relational Model 2. Week 3

Introduction to Data Management. Lecture #4 (E-R à Relational Design)

CSE 344 Midterm. Wednesday, February 19, 2014, 14:30-15:20. Question Points Score Total: 100

Midterm Exam (Version B) CS 122A Spring 2017

Relational Model. Topics. Relational Model. Why Study the Relational Model? Linda Wu (CMPT )

EECS-3421a: Test #2 Queries

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully.

UNIVERSITY OF TORONTO Faculty of Arts and Science. Midterm Sample Solutions CSC324H1 Duration: 50 minutes Instructor(s): David Liu.

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra

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

The Relational Model. Chapter 3

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement

CS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13

CSE 344 Midterm. November 9, 2011, 9:30am - 10:20am. Question Points Score Total: 100

Basant Group of Institution

Sankalchand Patel College of Engineering, Visnagar B.E. Semester III (CE/IT) Database Management System Question Bank / Assignment

The University of Nottingham

Database Management Systems,

CHALMERS UNIVERSITY OF TECHNOLOGY Department of Computer Science and Engineering Examination in Databases, TDA357/DIT620 Thursday 27 March 2008, 08:30

The Relational Model. Chapter 3. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

NOTE: DO NOT REMOVE THIS EXAM PAPER FROM THE EXAM VENUE

Data Modelling and Databases. Exercise Session 7: Integrity Constraints

The Relational Model

GUJARAT TECHNOLOGICAL UNIVERSITY

Ryan Marcotte CS 475 (Advanced Topics in Databases) March 14, 2011

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

COGS 121 HCI Programming Studio. Week 03 - Tech Lecture

Exam. Question: Total Points: Score:

DATABASE MANAGEMENT SYSTEMS

Transcription:

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2015 EXAMINATIONS CSC 343 H1S Instructor: Horton and Liu Duration 3 hours PLEASE HAND IN Examination Aids: None Student Number: Family Name(s): Given Name(s): # 1: / 6 # 2: / 12 # 3: / 6 # 4: / 13 In the SQL questions, you are welcome to use views. Comments are not required, although they may help us mark your answers. The last page of this exam is a reference page, containing schemas and a dataset. There is a blank page at the end for rough work. If you want any of it marked, indicate that clearly there, as well as in the question itself. A mark of at least 40 out of 100 on this exam is required in order to pass the course. # 5: / 8 # 6: / 6 # 7: / 15 # 8: / 6 # 9: / 4 # 10: / 6 # 11: / 6 # 12: / 6 # 13: / 4 # 14: / 6 TOTAL: /104 Page 1 of 24 Good Luck! cont d...

Question 1. [6 marks] Tear off the last page of the exam, which contains a reference sheet. Consider the Company schema given on the reference sheet. Answer the following questions about this schema, assuming the pure relational model: no duplicate tuples or NULLs allowed. Part (a) [2 marks] According to this schema, can one employee belong to more than one department? Circle one: Yes No Explain your answer in the space below. Part (b) [2 marks] Write an integrity constraint to enforce the following condition: for all pairs of employees A and B, if employee A manages employee B, then employee B cannot also manage employee A. Part (c) [2 marks] What would be the real-world implication of making {junior} a key of the Manages relation instead of {manager, junior}? Page 2 of 24 Student #: cont d...

Question 2. [12 marks] Write relational algebra expressions to make the following queries, using only the basic operators we used in class: Π, σ,,,,,, ρ, and assignment. Part (a) [5 marks] For each department, report the highest salary of any employee in that department. You may assume every department has at least one employee. Your output relation should have two attributes called did and highest. You should have one tuple per department. Page 3 of 24 Student #: cont d...

Part (b) [7 marks] We say that employee a dominates employee b if they are different employees and for every day in which b had a sales amount, a had a sales amount that was higher than b s sale amount. An employee who did not sell on any day is dominated by every other employee. Report all pairs of employees where one dominated the other. Your output relation should have two attributes called eid1 and eid2, where eid1 is the ID of the employee who dominates, and eid2 is the ID of the employee who is dominated. Hint: A good starting point is constructing a relation with all pairs of eids that are not the same, and another relation DominateDays(eID1, eid2, day) where eid1 sold a higher amount than eid2 on that day. Page 4 of 24 Student #: cont d...

Now answer some questions on the same schema, but in SQL. Question 3. [6 marks] Write a query in SQL that does the following. For each manager, find their junior with the greatest total sales. If there is a tie, report them all. Produce output with the form below; manager is the ID of the manager, and besttotal is the greatest total sales. manager besttotal ---------+----------- Page 5 of 24 Student #: cont d...

Question 4. [13 marks] Important: You may use the view defined in any subquestion (even if you didn t answer it) when solving other subquestions. It may help to define additional views. Part (a) [5 marks] For each department, find the number of employees with an unknown salary. Include departments in which no one s salary is unknown. (For them, the number of unknown salaries is, of course, zero.) Do not include departments which have no employees. Create a view for this query called DeptUnknowns, with the form below. Hint: You can use a constant, such as 0, in place of a column name in a SELECT statement. For example, this is legal: SELECT 1234 AS amount... FROM Sales... did unknowns -----+---------- Page 6 of 24 Student #: cont d...

Part (b) [4 marks] For each department, find the employee with the minimum salary (the poorest ). Report the department ID, the employee ID of the poorest employee from that department, and their salary. Note that an employee s salary may be unknown (that is, it may be recorded as NULL). If everyone in a department has a NULL salary, or if a department has no employees, that department will not appear in your result. Create a view for this query called DeptPoorest, with the form below. did poorest salary -----+---------+-------- Part (c) [4 marks] Write a query to report, for each department in the Departments table, the department ID, the ID and salary of the employee with the lowest salary, and the number of employees with an unknown salary. Don t leave any departments out! Your result must have the form below. department poorest salary unknowns ------------+---------+--------+---------- Page 7 of 24 Student #: cont d...

Question 5. [8 marks] Suppose I have a file called nonsense.ddl containing this: DROP SCHEMA IF EXISTS rp CASCADE; CREATE SCHEMA rp; SET SEARCH_PATH TO rp; CREATE TABLE Things ( A INT PRIMARY KEY, B INT, C INT UNIQUE ); CREATE TABLE Junk ( G INT PRIMARY KEY, H INT, I INT, FOREIGN KEY (I) REFERENCES Things(A) ON UPDATE CASCADE ON DELETE CASCADE ); CREATE TABLE Stuff ( D INT, E INT, F INT PRIMARY KEY, FOREIGN KEY (E) REFERENCES Things(C) ON UPDATE RESTRICT ON DELETE SET NULL, FOREIGN KEY (E) REFERENCES Junk(G) ON UPDATE SET NULL ON DELETE CASCADE ); Part (a) [2 marks] Suppose I imported this file into postgresql using the command \i nonsense.ddl and then a few weeks later the following happened when I tried to access table Junk. dbsrv1% psql csc343h-dianeh psql (9.1.15, server 9.1.14) Type "help" for help. csc343h-dianeh=> SELECT * FROM Junk; ERROR: relation "junk" does not exist LINE 1: SELECT * FROM Junk; ^ Modify my interaction above so that the SELECT statement works. Page 8 of 24 Student #: cont d...

Part (b) [2 marks] What is the most important thing that is the same about PRIMARY KEY and UNIQUE? What is one important difference between PRIMARY KEY and UNIQUE? Part (c) [2 marks] Suppose the tables have been populated as shown below. Modify the data to show the contents of the three tables after this command is executed: UPDATE Things SET C = 20 WHERE A = 8; Things: a b c ---+---+--- 3 2 3 4 2 5 8 2 6 1 5 4 9 8 7 2 2 9 Stuff: d e f ---+---+--- 3 4 1 1 6 3 2 9 5 2 3 4 Junk: g h i ---+---+--- 9 0 3 3 2 9 6 2 8 8 5 9 4 1 1 Part (d) [2 marks] Suppose we began with the same original tables, shown below, but ran a different command. Modify the data to show the contents of the three tables after this command is executed: DELETE FROM Things WHERE C = 3; Things: a b c ---+---+--- 3 2 3 4 2 5 8 2 6 1 5 4 9 8 7 2 2 9 Stuff: d e f ---+---+--- 3 4 1 1 6 3 2 9 5 2 3 4 Junk: g h i ---+---+--- 9 0 3 3 2 9 6 2 8 8 5 9 4 1 1 Page 9 of 24 Student #: cont d...

Quiz DTD This is a DTD representing questions on a quiz, and student responses for that quiz. <!ELEMENT quiz (questions, class-responses)> <!ELEMENT questions ((mc-question tf-question)+)> <!ELEMENT mc-question (question, option+)> <!ATTLIST mc-question qid ID #REQUIRED> <!ATTLIST mc-question solution CDATA #REQUIRED> <!ELEMENT question (#PCDATA)> <!ELEMENT option (#PCDATA)> <!ELEMENT tf-question (question)> <!ATTLIST tf-question qid ID #REQUIRED> <!ATTLIST tf-question solution (True False) #REQUIRED> <!ELEMENT class-responses (student+)> <!ELEMENT student (response+)> <!ATTLIST student sid ID #REQUIRED> <!ELEMENT response EMPTY> <!ATTLIST response qid IDREF #REQUIRED> <!ATTLIST response answer CDATA #REQUIRED> Page 10 of 24 Student #: cont d...

Question 6. [6 marks] Answer the following questions about the quiz DTD on the previous page. Part (a) [2 marks] Does this DTD enforce the constraint that every quiz contains at least one multiple-choice question and at least one true-false question? Circle one: Yes No Explain your answer. Part (b) [2 marks] What restrictions, if any, does the DTD enforce about the number of responses each student could have for the quiz? Part (c) [2 marks] Three attributes are listed in this DTD with ID data. What is the purpose of using ID? What makes IDs less powerful than keys in SQL? Page 11 of 24 Student #: cont d...

Question 7. [15 marks] Here is a standalone XML file called data.xml. It also appears on the reference page at the end of this exam. <?xml version="1.0" standalone="yes"?> <foo a="1"> <bar b="hi" c="5"> <baz a="15" /> <qux>data</qux> </bar> <bar b="good" c="4"> </bar> <bar b="bye"> <baz a="19" /> <baz a="10" /> <baz a="0" /> </bar> <bar b="greetings" c="1"> <qux>dream</qux> <qux>electric</qux> <baz a="16" /> <qux>sheep</qux> </bar> </foo> Each of the queries on the next two pages runs without errors. Show the output. We will not be grading the whitespace in your answer, but please use newlines and indentation appropriately to make the output easier to read. Note: the queries are NOT meant to make sense. If you think a query outputs nothing, say outputs nothing. If you think it outpus an empty sequence, simply write (). At least one of the queries doesn t successfully do what it is trying to do. Page 12 of 24 Student #: cont d...

Part (a) [3 marks] let $d := doc("data.xml") return ($d/foo/bar[@b="bye"], $d//qux[2]) Part (b) [3 marks] <docs>{ for $bar in doc("data.xml")/*/* where $bar/baz[@a < 16] return $bar/qux } </docs> Part (c) [3 marks] for $e in doc("data.xml")/*/* return <elem>data($e/@b)</elem> Page 13 of 24 Student #: cont d...

Part (d) [6 marks] let $z := <r> { for $q in doc("data.xml")//qux return if ($q/parent::bar/@c < 3) then <answer y="{data($q)}" /> else <answer y="none" /> } </r> let $f := doc("data.xml")//baz[@a >= 16] for $n in $z//@y for $m in $f//@a return <x>{($n,$m)}</x> Page 14 of 24 Student #: cont d...

Question 8. [6 marks] Consider relation R(A, B, C, D, E, F ) with functional dependencies S. S = {CD A, B EF, A BC, F D} Part (a) [1 mark] Above, circle all FDs that violate BCNF. Part (b) [2 marks] Add a second row to this instance of R that satisfies all its functional dependencies and has redundant data. Circle every value that could be erased and yet its value could be inferred. A B C D E F 1 2 3 4 5 6 Part (c) [2 marks] Show below what attributes would go into the two relations resulting from the first step of BCNF decomposition on R. (There may be several correct answers.) Do not project the functional dependencies onto the relations, just show the relations. Rough work: One new relation would have attributes: The other new relation would have attributes: Part (d) [1 mark] What important property does BCNF decomposition not guarantee? Question 9. [4 marks] Suppose we are employing the 3NF synthesis algorithm on a relation R(A, B, C, D, E, F ), and we already have the following minimal basis: S = {A C, BF D, DF C, EF D} I therefore propose that the following schema is the result of the 3NF synthesis algorithm: R1(A, C), R2(B, F, D), R3(D, F, C), and R4(E, F, D). But I am wrong. Why am I wrong? Justify all points in your answer. Correct my proposed schema, according to the 3NF synthesis algorithm. Explain all steps in your answer. Page 15 of 24 Student #: cont d...

Question 10. [6 marks] Consider relation R(A, B, C, D, E, F ) with functional dependencies S. S = {AC B, B ACE, BC E, BD AF, } Compute a minimal basis for S. Show your rough work, and put your final answer where shown on the next page. There will be no marks for a correct answer without the rough work. Rough work: Page 16 of 24 Student #: cont d...

A minimal basis is: Page 17 of 24 Student #: cont d...

Question 11. [6 marks] Suppose we are employing the 3NF synthesis algorithm on a relation R(A, B, C, D, E), and we already have the following minimal basis: Part (a) [3 marks] List all the keys for relation R: S = {A DE C A, E A} How do you know that nothing else is a key? Part (b) [2 marks] Show the final schema produced by the 3NF algorithm. Explain your answer in terms of the steps of the algorithm. Do not project the functional dependencies onto the relations, just show the relations. Part (c) [1 mark] What important property does 3NF synthesis not guarantee? Page 18 of 24 Student #: cont d...

Question 12. [6 marks] Part (a) [2 marks] Consider the table Parent(pID, cid, ageatbirth). A tuple in this relation records the fact that the person pid is a parent of the person cid, and the parent s age on the day their child was born is ageatbirth years. For each query below, circle Yes or No to indicate whether it can be expressed in the relational algebra we have been using in this course, i.e., with operators Π, σ,,,,,, ρ, and assignment. 1. Find the pid of the parent with the second-highest value for ageatbirth. Yes No 2. All pairs x, y where y is a descendent of x (any number of generations away). Yes No 3. Find the ID of the person with the most children. There may be ties; all such parents should be included. Yes No 4. Find the IDs of people with fewer than 6 children. Yes No Part (b) [2 marks] An error occurs if we attempt to create the following two tables: CREATE TABLE Person ( person_id PRIMARY KEY INT, name TEXT ); CREATE TABLE Contributions ( who TEXT, organization TEXT, hours INT, FOREIGN KEY (who) REFERENCES Person(name) ); All keywords and the statement syntax are correct, but we are asking to do something improper. Explain. Part (c) [2 marks] Can a relation with exactly three attributes violate BCNF? Circle one: Yes No If yes, give an example (a relation schema and its FDs) that violates BCNF. If no, explain why not. Page 19 of 24 Student #: cont d...

Question 13. [4 marks] Below is an Entity-Relationship diagram about car dealerships. It may or may not represent the domain well. Answer the questions below. dealership did dname VIN (1,N) model year car (0,1) works at salary (1,1) date amount sale (0, N) salesperson sid sname name email phone customer (0, N) 1. A car sale cannot involve more than one salesperson. True False 2. There can be two cars with the same VIN as long as the model and year are different. True False 3. A salesperson can work at any number of dealerships. True False 4. There can t be more salespeople than dealerships. True False 5. There can be multiple sales on the same date. True False 6. Two salespeople can have the same sid as long as they work at different dealerships. True False 7. This model contains a weak entity set. True False 8. The works at relationship is a one-to-many relationship. True False Page 20 of 24 Student #: cont d...

Question 14. [6 marks] Translate this Entity-Relationship diagram into a relational schema. For each relation, provide its name, attributes and keys. To indicate a key, underline all attributes that are part of the key using a single line. Also include all referential integrity constraints, using relational notation, not SQL notation. Page 21 of 24 Student #: cont d...

[Use the space below for rough work. This page will not be marked, unless you clearly indicate the part of your work that you want us to mark.] Page 22 of 24 Student #: cont d...

Reference Page tear off Company Schema This is a schema representing the organization of employees at a company. Relations Department(dID, name, division) Each tuple in this relation represents information about a different department in the company: its name, and which division it belongs to. Employee(eID, name, salary, dept) Each tuple in this relation represents information about a different employee in the company: their name, salary (amount of money earned per year), and which department the employee belongs to. Manages(manager, junior) Each tuple in this relation represents a relationship between two employee: manager is an employee who manages junior. Sales(eID, day, amount) Each tuple in this relation represents the total amount of sales made by an employee on a particular day. Integrity constraints Employee[dept] Department[dID] Manages[manager] Employee[eID] Manages[junior] Employee[eID] Sales[eID] Employee[eID] σ amount<0 Sales = σ salary<0 Employee =

Reference Page tear off Company schema in DDL CREATE TABLE Department( did INTEGER PRIMARY KEY, name TEXT NOT NULL, division INTEGER); CREATE TABLE Employee( eid INTEGER PRIMARY KEY, name TEXT NOT NULL, salary FLOAT, dept INTEGER REFERENCES Department(dID), CHECK(salary >= 0)); CREATE TABLE Manages( manager INTEGER REFERENCES Employee(eID), junior INTEGER REFERENCES Employee(eID), PRIMARY KEY(manager, junior)); CREATE TABLE Sales( eid INTEGER REFERENCES Employee(eID), day DATE, amount INTEGER, PRIMARY KEY(eID, day), CHECK(amount >= 0)); An XML dataset: data.xml <?xml version="1.0" standalone="yes"?> <foo a="1"> <bar b="hi" c="5"> <baz a="15" /> <qux>data</qux> </bar> <bar b="good" c="4"> </bar> <bar b="bye"> <baz a="19" /> <baz a="10" /> <baz a="0" /> </bar> <bar b="greetings" c="1"> <qux>dream</qux> <qux>electric</qux> <baz a="16" /> <qux>sheep</qux> </bar> </foo>