Week 2: Tutorial
1. The following table form part of a database held in a relational DBMS.
Hotel (hotelNo, hotelName, City)
Room (roomNo, hotelNo, type, price)
Booking (hotelNo, guestNo, datefrom, dateTo, roomNo)
Guest (guestNo, guestName, guestAddress, guestcardNo, expiryDate)
Using the above Hotel schema, determine whether the following queries are semantically correct.
a) SELECT [Link], [Link]
FROM Room r, Hotel h
WHERE r.hotel_number = h.hotel_number AND h.hotel_name = ‘Grosvenor Hotel’ AND
[Link] > 100;
b) SELECT [Link], [Link]
FROM Hotel h, Booking b, Guest g
WHERE [Link] = [Link] AND [Link] = ‘Grovesnor Hotel’;
c) SELECT [Link], [Link]
FROM Hotel h, Booking b, Room r
WHERE [Link] = [Link] AND [Link] = ‘H21’ AND [Link] = [Link] AND
Type = ‘S’ AND [Link] = ‘H22’;
2. Write the following queries based on the given relation schema.
Beers ( name, brewery)
Bars (name, addr, license)
Drinkers (name , addr, phone)
Likes( drinker, beer)
Sells (bar, beer, price)
Frequents (drinker, bar)
1. Find the address of Joe’s Bar
2. Find the beers produced by Labatt USA
3. Find the beers that are sold in Joe’s bar or at polar bar
4. Find all the beers priced at least 2£
5. Find the manufacturers of beers
6. Find the names of all beers that begin with letter ‘S’
7. Who drinks beers produced by Labatt USA
8. Count the distinct drinkers in Likes table.
3. Consider a relational data model for motor insurance policy management depicted below.
(a) Write an SQL statement to retrieve the first name and last name of all drivers who live in London
city.
(b) Write an SQL statement to list all policies which expire on 01/01/2017.
(c) Write an SQL statement to list all vehicles whose policy is worth more than ten thousand
pounds.
(d) Write an SQL statement to list the vehicle IDs owned for each driver licensed before 01/01/2009.