0% found this document useful (0 votes)
11 views6 pages

Midterm 2018

Uploaded by

oguztemelli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views6 pages

Midterm 2018

Uploaded by

oguztemelli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

NAME:

SABANCI UNIVERSITY
CS306 DATABASE SYSTEMS
MIDTERM EXAM
March 23rd, 2018
Duration: 110 minutes

 Do all your work on the exam paper. No extra sheets can be used.
 For your own protection, print your name at the top of each page.
 You may NOT use any book, notes, laptops, or other references for this exam.

Q1 5
Q2 5
Q3 10
Q4 15
Q5 20
Q6 5
Q7 25
Q8 5
Q9 15
Q10 15
TOTAL 120

Q1 [5pts] Mark the following statements as T (True) or F (False). You will lose 1pt for each
incorrect answer.

---- Strict two phase locking generates recoverable schedules.


---- Projection operator in relational algrebra can change the schema of the input relation
---- Weak entities can not exist by themselves without a parent entity.
-----Integrity Constraints must be satisfied for all instances of the database
---- Any serial execution of a set of transacions preserves the consistency of the database.

Q2[5pts] Fill in the blanks.

 If a transaction ...... it needs to roll back.

 When a transaction …… all its effects should be in the database.

 All the operations of a transaction needs to be recorded in the …… structure for


recovery

 A schedule is ……… if it is equivalent to a serial schedule.

 Value of foreign key should either exist in the parent table or it should be ..........
Q3 [10pts] Draw the ER diagram for the following specifications: There are football teams,
football players, and organizations. Each football player has a name, surname, age, and role
as attributes. Football players have unique name-surname combinations. Teams have names,
and city as attributes. Names of the teams are unique. Football players belong to teams. A
team may have multiple players, but a player belongs to at most one team. Organizations
sponsor teams. An organization may sponsor many teams and a team may be sponsored by
many organization. Each team must have a sponsor. Organizations are identified by their
name which is unique. (Please do not ask questions about this question and answer it with
respect to the specifications given above. If you make any assumptions, write them down)

Q4 [15] Convert the following ER model to relational model. Do not forget to indicate
primary and foreign keys. Make sure that you enforce all the constraints when designing the
schema. (Use the space around the ER model to write the create table table statements. You
may use the space after Q10 if needed).

Name
eeee

Code Address Address BranchNo


No

Bank Bank-Branch
Branches

Accounts

Account
AccountNo
No Balance
No

Acc-Cust

SSN

Name Customer Address


eee
Q5 [20pts] For the following relation schema

STUDENTS (SID, SNAME, AGE)


COURSES (CID, CNAME)
ENROLLED(SID,CID)

(a) [5pts] Write the relational algebra equivalent of the following statement : “List the
NAMEs of students who are enrolled in a course”.

(b) [5pts] Write the relational algebra equivalent of the following statement : “List the SIDs
of students who were enrolled in all courses”.

(c) [5pts] Write the relational algebra equivalent of the following statement : “List the SIDs
of students who were enrolled in exactly one course”.

(d) [5pts] Write the relational algebra equivalent of the following statement : “List the SIDs
of students with maximum AGE”.

Q6 [5pts] What does the following integrity constraint try to enforce? Also explain why the
intended integrity constraint cannot be enforced.

CREATE TABLE Sailors


( sid INTEGER,
sname CHAR(10),
rating INTEGER,
age REAL,
PRIMARY KEY (sid),
CHECK
( (SELECT COUNT (S.sid) FROM Sailors S)
+ (SELECT COUNT (B.bid) FROM Boats B) < 100 )
Answer the next question considering the schema below
TRANS(CID, TID , ITEMID)
CUSTOMER(CID, NAME, CITY)
ITEMS(ITEMID, ITEMNAME, PRICE)

CID TID ITEMID In the schema above, TRANS is the table that stores the
C1 T1 I3 transactions (meaning the set of items purchased at a time)
C1 T1 I4 with the items in those transactions. On the left is an
C2 T2 I1 instance of the TRANS table. For example, we see that C1
C2 T2 I2 bought items I3 and I4 in T1, and the same customer C1
C1 T3 I1 bough items I1 and I2 in T3. Details of customers are in
C1 T3 I2 CUSTOMER table and details of ITEMS are in ITEMS
C3 T4 I4 table.
C3 T4 I5

Q7 [25] Write the SQL statements for the following queries

(a) [5pts] List the total count of customers whose NAME starts with captial letter A
followed by any number of letters.

(b) [5pts] List the ITEMID and PRICE of items purchased by customers whose NAME is
“Ali”.

(c) [5pts] List the total price of items purchased by each customer (Display the CID and
the total price).

(d) [10pts] List CIDs of customers who purchased all the items.
Q8 [5pts] Assume that you have designed the following schema of relations:
COURSES (CID, CNAME)
STUDENTS(SID, SNAME, FAV_CIDS)
Where in STUDENTS relation, FAVORITE_COURSES are the set of CIDS of the courses
that the student likes. However, you can not have a relation with set valued attributes and you
need to convert it to a normal form. Name this normal form and indicate the resulting schema
(No need to write the create table statements)

Q9 [15pts] Answer the following questions regarding schema refinement and normal forms.
Make sure that you explain your answer. No explanation means no points.

(a) [2pts] For R(A,B,C,D,E) with FDs F = {A->B, B->C, AB->D, EC->D}. Is A->C implied
by F? Explain your answer.

(b) [3pts] For R(A,B,C,D,E) with FDs F = {A->B, B->C, AB->D, EC->D}. Find a key for
R with respect to F.

(c) [3pts] For R(A,B,C,D,E) with FDs F = {A->B, B->C, AB->D, EC->D}. What is the
attribute closure of A with respect to F?

(d) [2pts] For R(A,B,C) with FDs F = {A->B, B->C}, is AB a key for R? Explain your
answer.

(e) [5pts] For R(A,B,C) with FDs, F = {AC->BD, A->B, B->C, A->C}, what is the
minimal cover of these FDs. Show the steps of your solution.
Q10 [15pts] Consider the schema TEACH (STUDENT, COURSE, INSTRUCTOR) with the
following functional dependencies:

STUDENT COURSE INSTRUCTOR


INSTRUCTOR COURSE

(a) [5pts] Is this relation in BCNF? Explain your answer

(b) [5pts] Is the decomposition of the relation schema above to the following schemas
lossless join decomposition? Explain your answer considering the functional
dependencies provided above.
TEACH1(STUDENT, INSTRUCTOR) TEACH2(STUDENT, COURSE)

(c) [5pts] Is the decomposition of the relation schema above to the following schemas
dependency preserving decomposition? Explain your answer considering the functional
dependencies provided above.
TEACH1(STUDENT, INSTRUCTOR) TEACH2(STUDENT, COURSE)

You might also like