0% found this document useful (0 votes)
27 views4 pages

Databases Homework 4

The document outlines Homework 4 for a unit on databases and software development, focusing on updating tables using SQL. It includes tasks related to creating and manipulating Flight and Passenger tables, defining primary and foreign keys, and writing SQL statements for various operations. Additionally, it discusses a serialization technique called two-phase locking to ensure transaction integrity.

Uploaded by

Hamza Omar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views4 pages

Databases Homework 4

The document outlines Homework 4 for a unit on databases and software development, focusing on updating tables using SQL. It includes tasks related to creating and manipulating Flight and Passenger tables, defining primary and foreign keys, and writing SQL statements for various operations. Additionally, it discusses a serialization technique called two-phase locking to ensure transaction integrity.

Uploaded by

Hamza Omar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Homework 4 Updating tables using SQL

Unit 11 Databases and software development

Homework 4 Updating tables using SQL


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]


A composite primary key is a primary key made up of two or more fields that together uniquely
identify a record.

(b) Identify a foreign key in the tables above. What is the purpose of the foreign key? [2]

A foreign key is FlightID and Date in the Passenger table.


Purpose: To establish a link between Passenger and Flight, ensuring data integrity by only
allowing flight values that exist in the Flight table.

(c) Write an SQL statement to extract the passport numbers, surnames and firstnames of
all passengers on Flight BA401 on 12/11/2016. [5]

SELECT PassportNo, Surname, Firstname


FROM Passenger
WHERE FlightID = 'BA401' AND Date = '2016-11-12';

(d) Write an SQL statement to create the table Flight. [5]

CREATE TABLE Flight (


FlightID CHAR(5),
Date DATE,
DestinationID CHAR(4),
1
Homework 4 Updating tables using SQL
Unit 11 Databases and software development

PRIMARY KEY (FlightID, Date)


);

2
Homework 4 Updating tables using SQL
Unit 11 Databases and software development

(e) Write an SQL statement to create the table Passenger [5]

CREATE TABLE Passenger (


PassportNo CHAR(8) PRIMARY KEY,
Surname VARCHAR(20),
Firstname VARCHAR(20),
FlightID CHAR(5),
Date DATE,
FOREIGN KEY (FlightID, Date) REFERENCES Flight(FlightID, Date)
);

(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]

ALTER TABLE Passenger


ADD Telephone VARCHAR(16),
ADD Email VARCHAR(20);

(g) Write an SQL statement to delete the column email from the Passenger table. [2]

ALTER TABLE Passenger


DROP COLUMN Email;

(h) Write an SQL statement to insert a record for passenger Jo Harris, passport number
12345678. [2]

INSERT INTO Passenger (PassportNo, Surname, Firstname, FlightID, Date)


VALUES ('12345678', 'Harris', 'Jo', 'FL001', '2025-05-15');
3
Homework 4 Updating tables using SQL
Unit 11 Databases and software development

2. Name and briefly describe a serialisation technique which ensures that transactions do not
overlap in time and ensures that updates are not lost. [3]

Two-phase locking (2PL) is a technique that ensures transactions do not interfere with each
other. It has a growing phase, where locks are acquired but not released, and a
shrinking phase, where locks are released and no new locks can be acquired. This
ensures serializability and prevents lost updates.

TOTAL 28 marks

You might also like