Homework 5 Defining and updating tables
Unit 4 Exchanging data
1. The entities Flight and Passenger are linked in a one-to-many relationship.
The table Flight has the following compulsory fields:
FlightID CHAR (5) (Primary key field)
Date DATE (dd/mm/yy) (Primary key field)
DestinationID CHAR (4)
The table Passenger has the following compulsory fields:
PassportNo CHAR (8) (Primary key)
Surname VARCHAR (20) (Variable length)
Firstname VARCHAR (20) (Variable length)
FlightID CHAR (5)
Date DATE
(a) What is a composite primary key? Give an example. [2]
(b) Identify a foreign key in the tables above. What is the purpose of the foreign key? [2]
(c) Write an SQL statement to extract the passport numbers, surnames and firstnames of
all passengers on Flight BA401 on 12/11/2016. [5]
(d) Write an SQL statement to create the table Flight. [5]
1
Homework 5 Defining and updating tables
Unit 4 Exchanging data
(e) Write an SQL statement to create the table Passenger [5]
(f) Write an SQL statement to add two new columns for Telephone,
16 characters (variable length) and email, 20 characters (variable length) to the
Passenger table. [2]
(g) Write an SQL statement to delete the column email from the Passenger table. [2]
(h) Write an SQL statement to insert a record for passenger Jo Harris, passport number
12345678. [2]
TOTAL 25 marks