SQL Statements for Olympic Venue and Event Management

Answered using GPT-4o mini by AI Answer Generator

Question:

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.

  1. Give the SQL to create the VENUE table. Choose appropriate data types. None of the attributes should be allowed to be null. Include the primary key constraint. CREATE TABLE VENUE ( VenueName VARCHAR2(100) CONSTRAINT VenuePK PRIMARY KEY, Location VARCHAR2(255) NOT NULL, Capacity NUMBER(10) NOT NULL );
  2. Give the SQL to create the EVENT table. Use appropriate data types and include the primary key and foreign key constraints. Referential integrity should be set such that a venue may not be deleted from the database if there is an event recorded in it. CREATE TABLE EVENT ( EventName VARCHAR2(100) NOT NULL, VenueName VARCHAR2(100) NOT NULL, CONSTRAINT EventPK PRIMARY KEY (EventName), CONSTRAINT FK_Venue FOREIGN KEY (VenueName) REFERENCES VENUE(VenueName) ON DELETE CASCADE );
  3. Give the SQL to add the Maracana Stadium to the VENUE table. The stadium is located in Avenida Maracana and has a capacity of 78,838. INSERT INTO VENUE (VenueName , Location, capacity) VALUES ('Maracana Stadium', 'Avenida Maracana', 78838);
  4. Give the SQL to add an attribute Sport to EVENT. (Possible values include Athletics, Swimming, Tennis, etc).
  5. Give the SQL to record the fact that the Maracana Stadium now has capacity 80,000.
Answer:

Here are the SQL statements to address each of your questions based on the specifications provided:

  1. SQL to create the VENUE table:
CREATE TABLE VENUE (
    VenueName VARCHAR2(100) CONSTRAINT VenuePK PRIMARY KEY,
    Location VARCHAR2(255) NOT NULL,
    Capacity NUMBER(10) NOT NULL
);
  1. SQL to create the EVENT table:
CREATE TABLE EVENT (
    EventName VARCHAR2(100) NOT NULL,
    ScheduledStart TIMESTAMP NOT NULL,
    VenueName VARCHAR2(100) NOT NULL,
    CONSTRAINT EventPK PRIMARY KEY (EventName),
    CONSTRAINT FK_Venue FOREIGN KEY (VenueName) REFERENCES VENUE(VenueName) ON DELETE RESTRICT
);

(Note: The ON DELETE RESTRICT clause is used here to prevent deletion of a venue if there are events associated with it, as per your requirement.)

  1. SQL to add the Maracana Stadium to the VENUE table:
INSERT INTO VENUE (VenueName, Location, Capacity) 
VALUES ('Maracana Stadium', 'Avenida Maracana', 78838);
  1. SQL to add an attribute Sport to EVENT:
ALTER TABLE EVENT 
ADD Sport VARCHAR2(50) NOT NULL;
  1. SQL to record the fact that the Maracana Stadium now has a capacity of 80,000:
UPDATE VENUE 
SET Capacity = 80000 
WHERE VenueName = 'Maracana Stadium';

These SQL statements will create the necessary tables, insert data, modify the structure of the EVENT table, and update the capacity of the Maracana Stadium as specified.