SQL Lab Exercise
SQL Lab Exercise
SQL Lab Exercise
Using the South African Tour database tables in Figure 1 illustrated below, write SQL
statements to answer questions 1 to 5.
TOUR
Tour-Id Tour-Name Tour-Duration Fee
U89 Ushaka Marine World 2 R250
B45 Botha Hill 3 R300
S23 Suncoast Casino 2 R50
GUIDE
Guide-Id Guide-Name Guide-Address Date-Hired
209 Sipho Luthuli Avondale Road, Morningside 02 February 2005
356 Sarah Benson 12a Fir Avenue, Pinetown 06 June 2010
560 Lungile Nzama 23 Currie Road, Berea 15 October 2004
SCHEDULE
Tour-Id Guide-Id Schedule-Time Schedule-Date
S23 209 09h00 15 February 2019
S23 560 12h00 21 March 2019
B45 356 10h00 03 April 2019
1. Create a table name SCHEDULE. Enforce primary key and foreign key constraints
and all changes to the primary keys must be updated on foreign keys. Make sure all
other tables have been created.
2
Information Management 2 SQL Exercise
Solution
Using the South African Tour database tables in Figure 1 illustrated below, write SQL
statements to answer questions 1 to 5.
TOUR
Tour-Id Tour-Name Tour-Duration Fee
U89 Ushaka Marine World 2 R250
B45 Botha Hill 3 R300
S23 Suncoast Casino 2 R50
GUIDE
Guide-Id Guide-Name Guide-Address Date-Hired
209 Sipho Luthuli Avondale Road, Morningside 02 February 2005
356 Sarah Benson 12a Fir Avenue, Pinetown 06 June 2010
560 Lungile Nzama 23 Currie Road, Berea 15 October 2004
SCHEDULE
Tour-Id Guide-Id Schedule-Time Schedule-Date
S23 209 09h00 15 February 2019
S23 560 12h00 21 March 2019
B45 356 10h00 03 April 2019
1. Create a table name SCHEDULE. Enforce primary key and foreign key constraints
and all changes to the primary keys must be updated on foreign keys. Assume other
tables have been created already.
3
Information Management 2 SQL Exercise
UPDATE GUIDE
SET Date_Hired = '15-Sep-2003'
WHERE Guide_Id = '560';
5. Write the SQL code to list all guide names that start with the letter ‘S’.
select * from GUIDE where Guide_Name LIKE 'S%';
6. Write a query to produce total fee owed if a tourist wanted to tour all places.
4
Information Management 2 SQL Exercise
11. List the Tour-id, Schedule-Time, and Fee in descending order of Fee.
SELECT Tour.Tour_Id, Schedule_Time, Tour_Fee
FROM SCHEDULE, TOUR
WHERE SCHEDULE.Tour_Id = TOUR.Tour_Id
ORDER BY Tour_Fee DESC;