This assignment practices creating tables with SQL DDL. We will see later how to design the relational table structure. For this assignment, you are given what the table should look like, and you need to write the SQL DDL.
Write the SQL DDL to create the following 5 tables describing airports, airplanes, passengers, and flights:
-
An
Airplane
table where each airplane is identified by a field calledid
that is a string of up to 10 characters. Other attributes includemodel
(string up to 20 characters), and amanufacture date
. (1 mark) -
An
Airport
table where each airport has anid
of exactly 5 characters, aname
(up to 30 characters), and is located in acity
(up to 40 characters), aprovince
(up to 20 characters), and acountry
(up to 20 characters). (1.5 marks) -
A
Flight
table where each flight is identified by both anumber
(exactly 5 characters) anddeparture date/time
(DATETIME). Note that the flight number does not by itself identify a flight as airlines reuse flight numbers. A flight departs from one airport (departAirport
) and arrives at another (arriveAirport
). Besides the departure date/time, there is an expectedarrival date/time
, andactual departure time
andactual arrival time
. Each flight record also stores the airplaneid
of the plane. Make all foreign keys set to null on delete and cascade on update. (3 marks) -
A
Passenger
table where each passenger is identified by an integerid
. Also store afirst name
andlast name
(both up to 30 characters) and abirthdate
. Other attributes includestreet
(50 chars),city
(40 chars),province
(20 chars), andcountry
(20 chars). (1.5 marks) -
An
OnFlight
table that stores information about passengers on flights. Each record stores thepassenger id
,flight number
,flight departure date/time
, and aseat number
(exactly 4 characters). Make all foreign keys set to perform no action (generate error) on delete and cascade on update. (3 marks)
Write the SQL DDL to perform the following modifications to the database created in Question 1.
Insert the following records into the appropriate tables.
('AC911','Boeing 747', '2001-01-25')
('WJ455', 'Airbus A380', '2008-11-15')
('YLW','Kelowna Airport','Kelowna','British Columbia', 'Canada')
('YWG','Winnipeg Airport','Winnipeg','Manitoba', 'Canada')
('AC35', 'YLW', 'YWG', 'AC911', '2022-09-14 07:00:00', '2022-09-14 15:00:00', '2022-09-14 07:05:00', '2022-09-14 15:30:00')
('WJ111', 'YWG', 'YLW', 'WJ455', '2022-09-15 10:00:00', '2022-09-15 12:00:00', '2022-09-15 09:55:00', '2022-09-14 11:49:55')
(1, 'Joe', 'Smith', '1970-12-15', '1350 Springfield Road', 'Kelowna', 'British Columbia', 'Canada')
(2, 'Fred', 'Brothers', '1950-01-02', '22 Pembina Highway', 'Winnipeg', 'Manitoba', 'Canada')
(1, 'AC35', '2022-09-14 07:00:00', '1A')
(1, 'WJ111', '2022-09-15 10:00:00', '10C')
(2, 'AC35', '2022-09-14 07:00:00', '2A')
(2, 'WJ111', '2022-09-15 10:00:00', '10D')
-
Update passenger id
1
on flight'AC35'
on the7 a.m.
flight on'2022-09-14'
to be seat'2B'
rather than the current'1A'
. -
Delay all flights that depart Kelowna airport by 1 hour. (advance actual departure time) Note: To add an hour to a date use the syntax
DATE_ADD(your date field, INTERVAL 1 HOUR)
.
-
The Kelowna airport is destroyed! Remove it from the
Airport
table. Note the changes to the flight table due toSET NULL
foreign key action. -
Remove the unruly passenger
1
from flight'WJ111'
on the10 a.m.
flight on'2022-09-15'
. -
Delete all on flight records for
'Fred Brothers'
. Note: You do not have to use a subquery for this question but try if you can!
Submit on Canvas a complete DDL file with all commands or show the TA during virtual office hours.