Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 2

/* This CREATE statement is to create a Schema with name “ sports2022” */

1 CREATE SCHEMA sports2022;

/* This USE statement is to select the schema “ sports 2022” for the current session */

2 USE sports2022;

/* This CREATE TABLE statement is used to create a table with name “field”. This “field”
table includes two columns: fieldid and description.

The column “fieldid” is the primary key of the table and , its starting value is 1, and will
increment by 1 for each new record automatically*/

3 CREATE TABLE field (

4 fielded INT AUTO_INCREMENT NOT NULL PRINARY KEY,

5 description VARCHAR(100)

6 );

/* This ALTER TABLE statement is used to rename the field description to name*/

ALTER TABLE field RENAME description to name;

/* This ALTER TABLE statement is used to make the column name as the required field */

ALTER TABLE field ALTER COLUMN name VARCHAR(100) NOT NULL;

CREATE TABLE SportsMatch (

matchid NOT NULL,

OrderNumber int NOT NULL,

PersonID int,

PRIMARY KEY (OrderID),

FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)

CREATE TABLE sportsmatch (

matchid INT PRIMARY KEY,

match_name VARCHAR(100) NOT NULL,

City VARCHAR(100) NOT NULL,


field_id INT,

FOREIGN KEY (field_id) REFERENCES field(fieldid)

);

INSERT INTO field VALUES (1, ‘Loftus’ );

INSERT INTO field VALUES (2, ‘FNB Stadium’);

You might also like