Question 3: Further oracle 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 TIMESTAMP 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 a new venue: The INSERT
statement adds the Maracana Stadium to the VENUE
table with its location and capacity.
Adding a new attribute: The ALTER TABLE
statement adds a new column Sport
to the EVENT
table, which is set to NOT NULL.
Updating the venue's capacity: The UPDATE
statement modifies the capacity of the Maracana Stadium to 80,000.
You can run these SQL statements in an Oracle SQL environment to create the tables, insert data, and modify the schema as specified.