You are on page 1of 6

NAME: STUDENT NUMBER:

COSC 3P32 MIDTERM EXAMINATION


FEBRUARY 14TH, 2019

Time: 9:00 a.m. – 10:30 a.m.


Total marks: 40

No electronic or written materials are permitted.


Answer all questions in this exam booklet.

Question Value Mark


1 9
2 10
3 21
Bonus 1
Total: 40
Question 1 – Definitions and Short Answer [9 marks]

a) [2x2 marks] What is a view and how does it differ from a relation? Give one reason why a view
might be used.

b) [2 marks] Briefly describe what a write-ahead log (WAL) is, and how it is used.

c) [3 marks] Consider the relation EnrolledIn(sid, cid, grade). This relation stores information on
students (identified by sid) enrolled in courses (identified by cid), and the grade the student
obtained in that course. Suppose that the key of the relation were changed to just sid. How does
this change the semantics (meaning) of the data?
Question 2 – ER Diagrams and the Relational Model [10 Marks]
Consider the following ER diagram:

model year seats

Vehicle

ISA towcap
trunksize

Car Truck

The above diagram represents information pertaining to vehicles. Some vehicles are cars, and for
these, we also wish to know trunk size; some other vehicles are trucks, and for these, we also wish
to know towing capacity (towcap).

a) [2x2 marks] Identify suitable overlap and covering constraints and briefly justify your
decisions.

b) [6 marks] Write the SQL statements to create the necessary tables to represent the above
diagram, representing as many constraints as possible. Note: you do not need to worry about
specifying types for the fields, but you do need to provide suitable foreign key options.
Question 2, continued (workspace)
Question 3 – Queries [21 Marks]
Consider the following database schema:
Student(sid, sname, major)
EnrolledIn(sid, cid, grade)
Course(cid, cname, dept, credits)
In the above schema, Student lists information on all students, Course lists information on all
courses, and EnrolledIn specifies which students have taken which courses, along with their grade.

a) [2x3 marks] Express the following query in both (i) Relational Algebra and (ii) SQL:
Find the majors of students enrolled in the course named “Databases”.

(i)

(ii)

b) [2x3 marks] Express the following query in both (i) Relational Algebra and (ii) SQL:
Find the sids of students who are not enrolled in any course.

(i)

(ii)
Question 3, continued.
c) [2x3 marks] Express the following query in both (i) Relational Algebra and (ii) SQL:
Find the sids of students enrolled in all courses in the Computer Science department

(i)

(ii)

d) [3 marks] Express the following query in SQL only:


For each cid listed in EnrolledIn, find the average grade obtained in the course with that cid.

Bonus Question [1 mark]: What is returned by the following query?


sid(sname = ‘Fred’ ^ sname = ‘George’ (Student))

You might also like