2nd Unit
2nd Unit
2nd Unit
2. A relational schema for a train reservation database is given below. Passenger (pid, pname,
age) Reservation (pid, class, tid)
Table: Passenger
pid pname age
-----------------
0 Sachin 65
1 Rahul 66
2 Sourav 67
3 Anil 69
Table : Reservation
pid class tid
---------------
0 AC 8200
1 AC 8201
2 SC 8201
5 AC 8203
1 SC 8204
3 AC 8202
What pids are returned by the following SQL query for the above instance of the tables?
SELECT pid
FROM Reservation ,
WHERE class ‘AC’ AND
EXISTS (SELECT *
FROM Passenger
WHERE age > 65 AND
Passenger. pid = Reservation.pid)
A. 1, 0
B. 1, 2
C. 1, 3
D. 1, 5
4. SQL allows tuples in relations, and correspondingly defines the multiplicity of tuples in the
result of joins. Which one of the following queries always gives the same answer as the nested
query shown below:
select * from R where a in (select S.a from S)
A. select R.* from R, S where R.a=S.a (D)
B. select distinct R.* from R,S where R.a=S.a
C. select R.* from R,(select distinct a from S) as S1 where R.a=S1.a
D. select R.* from R,S where R.a=S.a and is unique R
6. Consider the relation account (customer, balance) where customer is a primary key and there
are no null values. We would like to rank customers according to decreasing balance. The
customer with the largest balance gets rank 1. ties are not broke but ranks are skipped: if exactly
two customers have the largest balance they each get rank 1 and rank 2 is not assigned
Query1:
select A.customer, count(B.customer)
from account A, account B
where A.balance <=B.balance
group by A.customer
Query2:
select A.customer, 1+count(B.customer)
from account A, account B
where A.balance < B.balance
group by A.customer
Consider these statements about Query1 and Query2.
1. Query1 will produce the same row set as Query2 for
some but not all databases.
2. Both Query1 and Query2 are correct implementation
of the specification
3. Query1 is a correct implementation of the specification
but Query2 is not
4. Neither Query1 nor Query2 is a correct implementation
of the specification
5. Assigning rank with a pure relational query takes
less time than scanning in decreasing balance order
assigning ranks using ODBC.
Which two of the above statements are correct?
A. 2 and 5
B. 1 and 3
C. 1 and 4
D. 3 and 5
7. The relation book (title, price) contains the titles and prices of different books. Assuming that
no two books have the same price, what does the following SQL query list?
select title
from book as B
where (select count(*)
from book as T
where T.price > B.price) < 5
A. Titles of the four most expensive books
B. Title of the fifth most inexpensive book
C. Title of the fifth most expensive bookTitles of the five most expensive books
D. Titles of the five most expensive books
Student(EnrollNo, Name)
Course(CourseID, Name)
EnrollMents(EnrollNo, CourseID)