3 P32 Midterm 2019
3 P32 Midterm 2019
3 P32 Midterm 2019
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:
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)