CMPT 354 (Summer, 1998) -- Midterm Exam (60 minutes)
Exam date: Thursday, July 2 Total scores: 100
In a company database, you need to store information about employees (identified by social insurance number, with salary and phone number as attributes), departments (identified by department number, with department name and budget as attributes), and children of employees (with name and age as attributes). Employees work in departments; each department is managed by an employee; a child can only be identified uniquely (by name) when the parent (who is an employee) is known. Assume that only one parent works for the company. We are not interested in information about a child once the parent leaves the company.
Answer
Answer
CREATE TABLE employees | (SIN char(11), salary numeric(8,2), phone char(13), PRIMARY KEY (SIN)) |
CREATE TABLE departments | (dno integer, dname char(20), budget numeric(10,2), PRIMARY KEY (dno))
|
CREATE TABLE works_in | (SIN char(11), dno integer, PRIMARY KEY (SIN,dno), FOREIGN KEY (SIN) REFERENCES employees ON DELETE CASCADE, FOREIGN KEY (dno) REFERENCES departments ON DELETE CASCADE )
|
CREATE TABLE children | (SIN char(11) NOT NULL, name char(30) NOT NULL, age integer, PRIMARY KEY (SIN,NAME), FOREIGN KEY (SIN) REFERENCES employees ON DELETE CASCADE ) |
Answer
DELETE * FROM employees WHERE SIN="321 654 987"
There is no need to delete tuples from Children, works_in or manages because of "ON DELETE CASCADE" clause.
Suppliers(sid, sname, city)
Parts(pid, pname, colour, weight)
Catalog(sid, pid, cost)
The Catalog relation lists the prices charged for parts by the suppliers.
Express the following queries in SQL:
Answer
SELECT P.pname FROM Parts P, Catalogue C WHERE P.pid = C.pid
Answer
SELECT S.sname FROM Suppliers S WHERE NOT EXIST ((SELECT P.pid FROM Parts P) EXCEPT (SELECT C.pid FROM Catalogue C WHERE C.sid=S.sid))
Answer
SELECT DISTINCT C.sid FROM Catalogue C WHERE C.cost > (SELECT Avg(K.cost) FROM Catalogue K WHERE K.pid=C.pid)
Answer
SELECT DISTINCT C.sid FROM Catalogue C, Parts P WHERE C.pid = P.pid AND P.colour="Red" UNION SELECT DISTINCT K.sid FROM Catalogue K, Parts R WHERE K.pid = R.pid AND R.colour="Green"
Answer
Suppliers | sid | sname | city |
---|---|---|---|
P. | _S | Vancouver |
Parts | pid | pname | colour | weight |
---|---|---|---|---|
  | _P | Green |
Catalogue | sid | pid | cost |
---|---|---|---|
_S | _P |
Answer
Suppliers | sid | sname | city |
---|---|---|---|
_S1 _S2 | Vancouver Burnaby |
Parts | pid | pname | colour | weight |
---|---|---|---|---|
  | _P | P. | P. |
Catalogue | sid | pid | cost |
---|---|---|---|
_S1 _S2 | _P _P |
Answer
BCD, ACD, and ECD are keys of R.
Answer
Yes, R is in 3NF because B, E, and A are all parts of keys.
Answer
No, R is in not in BCNF because none of A, BC and ED contain a key.
I like the exams this style 66% I dislike the exams this style 34% I prefer one big problem to solve 5% I prefer some separate questions 40% I prefer multiple small questions 55% The questions are too hard 62% The questions are too easy 0% The questions are just right 38% I have plenty of time to finish the questions 5% I have just enough time to finish the questions 11% I do not have enough time to finish the questions 84%