Midtermxx
Midtermxx
Midtermxx
The exam is open book and open notes; any written materials may be used.
There are four parts on the exam, with a varying number of points for a total of 75 points.
There are also two extra-credit questions with a total of 10 points. You should look through
the entire exam before getting started, in order to plan your strategy. You have 75 minutes to
complete the exam.
Unless otherwise specified, assume that all relations are duplicate-free in questions not re-
lated to SQL. All questions about SQL refer to the SQL2 or SQL3 standard, not necessarily
to the Oracle implementation of SQL used in programming assignments.
NAME:
In accordance with both the letter and spirit of the Honor Code, I have neither given nor received
assistance on this examination.
SIGNATURE:
A R B A R B
(A) T S (B) T S
C C
A R B A R B
(C) T S (D) T S
C C
Answer:
A B
C D
Suppose the key of entity set A is attribute , the key of B is , the key of C is , and the key of
D is . If we translate relationship set R into a relation , what are all the keys of ?
(A)
(B) , , and
(C)
(D) , , and
Answer:
Question 3: (4 points) Suppose that we convert the above E/R diagram into relations using the
E/R-style translation for subclasses. What will we get for the ConferenceRooms entity set?
(A) ConferenceRoom(capacity)
(B) ConferenceRoom(room number, capacity)
(C) ConferenceRoom(building name, room number, capacity)
(D) ConferenceRoom(building name, room number, area, capacity)
Answer:
Question 4: (4 points) Suppose that we have specified an ODL schema that captures the design
of the above E/R diagram. We then convert the ODL schema into three relations BuildingODL ,
RoomODL , and ConferenceRoomODL , using the ODL-style translation for subclasses. Suppose
there are rooms in the database, and among these, are conference rooms. How many tuples
are in relations RoomODL and ConferenceRoomODL , respectively?
(A) and (B) and (C) and (D) 0 and
Answer:
Question 5: (4 points) Which of the following statements are true according to the constraints
encoded by the E/R diagram above? Do not make any assumptions other than those encoded by
the E/R diagram.
I. The number of entities in the Rooms entity set must be greater than or equal to the number
of entities in the ConferenceRooms entity set
II. The number of entities in the Rooms entity set must be greater than or equal to the number
of entities in the Buildings entity set
(A) I only (B) II only (C) Both I and II (D) Neither I nor II
Answer:
Question 6: (4 points) In the instance of the relation shown below, which of the
following functional dependencies (FD’s) hold?
1 2 3 4 5
1 4 3 4 5
1 2 4 4 1
I. II. III.
(A) I only (B) II only (C) I and III only (D) II and III only
Answer:
Unfortunately we don’t know what is—it could be any nonempty subset of ’s attributes. (In
particular, might even contain itself, which would make a trivial dependency.)
Question 10: (4 points) Which of the following must be true regardless of what is inside ?
(A) Every key of contains
(B) No key of contains
(C) Some key of contains while some other key does not
(D) None of the above
Answer:
Question 11: (4 points) Which of the following must be true regardless of what is inside ?
(A) Every key of contains
(B) No key of contains
(C) Some key of contains while some other key does not
(D) None of the above
Answer:
Question 12: (4 points)[extra credit] Which of the following must be true regardless of what is
inside ?
I. If some key of contains , then some other key must contain
II. If some key of contains , then some other key must contain
(A) I only (B) II only (C) Both I and II (D) Neither I nor II
Answer:
Question 13: (4 points) Suppose that two relations and have exactly the same
schema. Which of the following equalities hold in relational algebra?
I.
II.
III.
(A) I only (B) I and II only (C) I, II, and III (D) None of the above
Answer:
Question 14: (4 points) Suppose we have two relations and with the same
schema. The only key of is ; the only key of is as well. Let relation be the
set union of and , i.e., . What are the keys of ?
(A) (B) (C) and (D)
Answer:
Question 15: (4 points) Suppose we wish to find the SSN’s of the persons who do not own stocks
of their employers. Which of the following queries will return the correct set of SSN’s?
I. SSN employerSymbol symbol Person Holding
II. SSN SSN sym P SSN sym sal Person SSN sym H SSN sym num Holding
III. SELECT SSN
FROM Person
WHERE employerSymbol <> ALL
(SELECT symbol FROM Holding WHERE Person.SSN = Holding.SSN);
(A) II only (B) I and II only (C) I and III only (D) II and III only
Answer:
Question 16: (4 points) Suppose we wish to find the average salary of the persons who own more
than 100 shares of Microsoft (MSFT) or more than 100 shares of Yahoo! (YHOO). Which of the
following queries will correctly compute the desired average?
I. SELECT AVG(salary)
FROM Person
WHERE SSN IN (SELECT SSN FROM Holding
WHERE (symbol = ’MSFT’ OR symbol = ’YHOO’)
AND numShares > 100);
(A) I only (B) II only (C) Both I and II (D) Neither I nor II
Answer:
Question 18: (5 points) Write a SQL query to find the total number of shares of Oracle (ORCL)
stock owned by Informix (IFMX) employees.
Question 20: (6 points)[extra credit] Let us define a “widely-held” stock to be one that is owned
by more than 40% of the investors in our database. Write a SQL query to find the latest closing
price for each widely-held stock. Note that some quotes may be delayed: for example, the latest
closing price of Microsoft stored in our database might be one day old, while the latest closing
price of Macrohard might be two days old.