0% found this document useful (0 votes)
16 views

cs3402_final mock exam_2023_solution

The document contains a series of questions and answers regarding SQL queries, relational algebra, functional dependencies, candidate keys, normal forms, and transaction scheduling. It includes specific queries for retrieving speaker and conference information, as well as a discussion on database normalization and transaction locking protocols. The answers provide SQL and relational algebra solutions, candidate key identification, normal form assessments, and a choice of transaction scheduling method.

Uploaded by

gilmourdenis65
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

cs3402_final mock exam_2023_solution

The document contains a series of questions and answers regarding SQL queries, relational algebra, functional dependencies, candidate keys, normal forms, and transaction scheduling. It includes specific queries for retrieving speaker and conference information, as well as a discussion on database normalization and transaction locking protocols. The answers provide SQL and relational algebra solutions, candidate key identification, normal form assessments, and a choice of transaction scheduling method.

Uploaded by

gilmourdenis65
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Question 1 [20 pts]

Consider the following relations for keeping track of speakers, conferences,


and presentations given by speakers at conferences:

Speaker( SID: integer, FName: string, LName: string)


Conference(CID:integer,CName:string, CLocation:string,CYear:interger)
Presentation( SID: integer, CID: integer )

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.

Give a SQL query and a query in relational algebra.

(2) Retrieve the names of all conferences where speakers with the first name
'James' gave a presentation that took place in 'Houston''.

Give a SQL query and a query in relational algebra.

(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.

Give a SQL query and a query in relational algebra.

* 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'

π Fname( FName='James' AND Location='Houston' (Speaker * Presentation * Conference))

(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’);

Tim_CID ← π CID( FName=‘Tim’ (Speaker * Presentation))

π LName(Speaker * Presentation * Tim_CID)

Question 2 [15 pts]


Suppose we have a relational database table R for the published books,
consisting of the following attributes:

I(ISBN number), T(Book_title), N(Author_name), Y(Book_type), M(List_price),


A(Author_affil), P(Publisher)

with the following functional dependencies:

{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:

(1) R has two cand. keys: {I} and {T,N}

(2)

R1 has a candidate key T. It is in 2NF but not 3NF, since M transitively


depends on T, i.e. T->Y->M.

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.

Overall, this decomposition is in 2NF but not 3NF.

(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)

Question 3 [15 pts]

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.)

Enter your answer using a two-column table.

(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.)

Enter your answer using a two-column table.

(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

(3) C2PL since it does not have the deadlock problem.

You might also like