Commit 90cee3c5 authored by Sorrel Harriet's avatar Sorrel Harriet

prepping schema definition for week-7 lab

parent d332fe9d
/* Make sure tables don't exist before creation */
DROP TABLE IF EXISTS orderline, transaction, customer, record, artist;
/* Define table for storing artists */
CREATE TABLE artist (
id INT AUTO_INCREMENT,
first_name VARCHAR(50),
last_name VARCHAR(50),
PRIMARY KEY(id)
) ENGINE=InnoDB;
/* Define table for storing records (products) */
CREATE TABLE record (
ean CHAR(8) NOT NULL,
title VARCHAR(50) NOT NULL,
artist_id INT,
genre VARCHAR(50),
year YEAR(4),
price_gbp DECIMAL(10, 2) unsigned NOT NULL,
price_eu DECIMAL(10, 2) unsigned NOT NULL,
avg_rating DECIMAL(10, 1) unsigned,
PRIMARY KEY (ean),
FOREIGN KEY (artist_id)
REFERENCES artist (id)
ON DELETE CASCADE
) ENGINE=InnoDB;
/* Define table for storing customers */
CREATE TABLE customer (
id INT AUTO_INCREMENT,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
email_address VARCHAR(50) NOT NULL,
address VARCHAR(50) NOT NULL,
city VARCHAR(50),
postcode VARCHAR(10) NOT NULL,
wishlist TEXT,
PRIMARY KEY (id)
) ENGINE=InnoDB;
/* Define table for storing orders */
CREATE TABLE transaction (
id INT AUTO_INCREMENT,
customer_id INT NOT NULL,
delivery_method INT,
dt_date DATETIME,
PRIMARY KEY (id),
FOREIGN KEY (customer_id)
REFERENCES customer(id)
) ENGINE=InnoDB;
/* Define table for storing orderlines */
CREATE TABLE orderline (
id INT AUTO_INCREMENT,
transaction_id INT,
record_ean CHAR(8),
quantity INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (transaction_id)
REFERENCES transaction(id),
FOREIGN KEY (record_ean)
REFERENCES record(ean)
ON UPDATE CASCADE
ON DELETE CASCADE
) ENGINE=InnoDB;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment