Question 3: Further SQL (15 marks) You have been given the following specifications of a simple database for keeping track of venues and events at the Olympics (note that primary keys are shown underlined, foreign keys in bold).
You should run your SQL to demonstrate that it works correctly.
VENUE (VenueName, Location, Capacity)
EVENT (EventName, ScheduledStart, VenueName)
Based on the table specifications provided, answer the following questions. Each question is worth 3 marks.
Here are the SQL statements to fulfill the requirements specified in your questions:
CREATE TABLE VENUE (
VenueName VARCHAR(100) NOT NULL,
Location VARCHAR(100) NOT NULL,
Capacity INT NOT NULL,
PRIMARY KEY (VenueName)
);
CREATE TABLE EVENT (
EventName VARCHAR(100) NOT NULL,
ScheduledStart DATETIME NOT NULL,
VenueName VARCHAR(100) NOT NULL,
PRIMARY KEY (EventName, ScheduledStart),
FOREIGN KEY (VenueName) REFERENCES VENUE(VenueName) ON DELETE RESTRICT
);
INSERT INTO VENUE (VenueName, Location, Capacity)
VALUES ('Maracana Stadium', 'Avenida Maracana', 78838);
ALTER TABLE EVENT
ADD Sport VARCHAR(50) NOT NULL;
UPDATE VENUE
SET Capacity = 80000
WHERE VenueName = 'Maracana Stadium';
Creating the VENUE table: The VENUE
table is created with three attributes: VenueName
, Location
, and Capacity
. All attributes are set to NOT NULL, and VenueName
is defined as the primary key.
Creating the EVENT table: The EVENT
table is created with three attributes: EventName
, ScheduledStart
, and VenueName
. The primary key is a composite key consisting of EventName
and ScheduledStart
. The foreign key constraint ensures that a venue cannot be deleted if there are events associated with it.
Inserting Maracana Stadium: This SQL statement inserts a new record into the VENUE
table for the Maracana Stadium with its location and capacity.
Adding the Sport attribute: This statement alters the EVENT
table to add a new column Sport
, which is set to NOT NULL.
Updating the capacity of Maracana Stadium: This SQL statement updates the capacity of the Maracana Stadium to 80,000 in the VENUE
table.
You can run these SQL statements in a database management system that supports SQL to demonstrate that they work correctly.