cs3402_final mock exam_2023_solution
cs3402_final mock exam_2023_solution
In the questions below, you need to write queries in SQL and in relational
algebra.
(1) Retrieve the first and last names of all speakers that gave a presentation
during the years 1995-2005.
(2) Retrieve the names of all conferences where speakers with the first name
'James' gave a presentation that took place in 'Houston''.
(3) List the last names of all speakers who gave a talk at a conference where a
speaker with the first name 'Tim' gave a talk.
* Solution is not unique. One possible solution is given for each question.
Answer:
(1)
SELECT Fname,Lname
FROM Speaker S ,Presentation P ,Conference C
WHERE S.SID=P.SID AND C.CID=P.CID
AND (CYear BETWEEN '1995' AND '2005')
π Fname,Lname( CYear≥'1995' AND CYear≤'2005'(Speaker * Presentation * Conference))
(2)
SELECT Fname
FROM Speaker S, Presentation P, Conference C
WHERE S.SID = P.SID AND C.CID = P.CID
AND S.FName='James'
AND C.Location='Houston'
(3)
SELECT LName
FROM Speaker S1, Presentation P1
WHERE S1.SID = P1.SID AND P1.CID IN
(SELECT CID
FROM Speaker S2, Presentation P2
WHERE S2.SID = P2.SID AND FName=‘Tim’);
{I → T, I → N, T → Y, Y → M, N → A, T → P, TN → I}.
(1) Find all the candidate keys for the relation table R.
(2) Determine the highest normal form the following decomposition is in 3NF.
Justify your answer with a brief explanation.
R1(T, Y, M, P)
R2(N, A)
R3(I, T, N)
(3) Come up with a decomposition for R so that the tables are in Boyce-Codd
normal form (BCNF).
Answer:
(2)
R2 has a candidate key N. It is in BCNF, since for every FD in R2, the left
landside is the superkey.
R3 has two candidate key I and TN. It is in BCNF, since for every FD in R3, the
left landside is the superkey.
(3)
R1(T, Y, P)
R2(N, A)
R3(I, T, N)
R4 (Y,M)
Based on the answer of 2), R2 and R3 are already in BCNF, so we only need to
split R1 into two tables: (T,Y,P) and (Y,M)
The following table shows the schedule for transactions T1 and T2 with T1
having an “older” time-stamp than T2.
T1 T2
Read(a)
Read(b)
Write(b)
Write(a)
(1) Add lock and unlock operations to the schedule if Conservative 2PL is
adopted. (Show the mode of the lock operation and also include the lock
operations that are unsuccessful.)
(2) Add lock and unlock operations to the schedule if Strict 2PL is adopted.
(Show the mode of the lock operation and also include the lock operations that
are unsuccessful.)
(3) Which one (S2PL or C2PL) will you choose for scheduling the two
transactions? Briefly explain your answer.
Answer:
(1)
T1 T2
ReadLock(a) success
WriteLock(b) success
Read(a)
Readlock(b) blocked
Writelock(a) blocked
Write(b)
Unlock(a,b)
Readlock(b) success
WriteLock(a) success
Read(b)
Write(a)
Unlock(a,b)
(2)
T1 T2
ReadLock(a) success
Read(a)
ReadLock(b) success
Read(b)
WriteLock(b) blocked
WriteLock(a) blocked