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 create the VENUE
and EVENT
tables based on the specifications provided:
CREATE TABLE VENUE (
VenueName VARCHAR2(100) CONSTRAINT VenuePK PRIMARY KEY,
Location VARCHAR2(255) NOT NULL,
Capacity NUMBER(10) NOT NULL
);
This SQL statement creates the VENUE
table with three columns: VenueName
, Location
, and Capacity
. The VenueName
column is defined as the primary key, and none of the columns are allowed to be null.
CREATE TABLE EVENT (
EventName VARCHAR2(100) NOT NULL,
ScheduledStart TIMESTAMP NOT NULL,
VenueName VARCHAR2(100) NOT NULL,
CONSTRAINT EventPK PRIMARY KEY (EventName, ScheduledStart),
CONSTRAINT FK_Venue FOREIGN KEY (VenueName) REFERENCES VENUE(VenueName) ON DELETE RESTRICT
);
In this SQL statement, the EVENT
table is created with three columns: EventName
, ScheduledStart
, and VenueName
. The primary key is a composite key consisting of EventName
and ScheduledStart
. The VenueName
column is defined as a foreign key that references the VenueName
column in the VENUE
table. The ON DELETE RESTRICT
clause ensures that a venue cannot be deleted if there are events associated with it, maintaining referential integrity.
These SQL statements should work correctly in a database management system that supports the SQL syntax used here, such as Oracle or Postgre