SQL Statements for VENUE and EVENT Tables

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.
Answer:

Here are the SQL statements to create the VENUE and EVENT tables 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
);

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.

  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, 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