Skip to content
Snippets Groups Projects
Commit 7912fa15 authored by Sorrel Harriet's avatar Sorrel Harriet
Browse files

initial work on example schema

parent ac74cf75
Branches
No related merge requests found
/* Delete existing tables in reverse order of creation
so as not to violate any foreign key constraints */
DROP TABLE IF EXISTS OrderLine, Order, Customer, Track, Album, Artist, Act, Genre;
/* Define table for genres */
CREATE TABLE Genre (
id INT AUTO_INCREMENT,
name VARCHAR(25) UNIQUE NOT NULL,
PRIMARY KEY (id)
}
/* Define table for storing act (i.e. a group or solo artist) */
CREATE TABLE Act (
id INT AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
genre_id INT,
PRIMARY KEY (id),
FOREIGN KEY (genre_id)
REFERENCES Genre (id)
}
/* Define table for storing artists */
CREATE TABLE Artist (
id INT AUTO_INCREMENT,
first_name VARCHAR(25) NOT NULL,
last_name VARCHAR(25),
act_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (act_id)
REFERENCES Act (id)
);
/* Define table for storing albums */
CREATE TABLE Album (
id INT AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
year YEAR(4),
compilation BOOLEAN NOT NULL DEFAULT 0
price DECIMAL(5, 2) unsigned NOT NULL,
}
/* Define table for storing single tracks */
CREATE TABLE Track (
id INT AUTO_INCREMENT,
title VARCHAR(50) NOT NULL,
act_id INT NOT NULL,
album_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (act_id)
REFERENCES Act (id),
FOREIGN KEY (album_id)
REFERENCES Album (id)
);
/* Define table for storing customers */
CREATE TABLE Customer (
id INT AUTO_INCREMENT,
username VARCHAR(25) UNIQUE NOT NULL,
email_address VARCHAR(50) UNIQUE NOT NULL,
password VARCHAR(64),
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
address_1 VARCHAR(50) NOT NULL,
address_2 VARCHAR(50),
postcode VARCHAR(10) NOT NULL,
PRIMARY KEY (id)
);
/* Define table for storing orders */
CREATE TABLE Order (
id INT AUTO_INCREMENT,
customer_id INT NOT NULL,
delivery ENUM('first class','second class','next working day'),
PRIMARY KEY (id),
FOREIGN KEY (customer_id)
REFERENCES Customer(id)
);
/* Define table for storing orderlines */
CREATE TABLE OrderLine (
id INT AUTO_INCREMENT,
order_id INT NOT NULL,
album_id INT NOT NULL,
quantity INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (order_id)
REFERENCES Order(id),
FOREIGN KEY (album_id)
REFERENCES Album(id),
);
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