Last active
August 29, 2015 14:16
-
-
Save saxbophone/e78f567db7a2297f4b78 to your computer and use it in GitHub Desktop.
Mia's Sandwich Shop SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE Orders( | |
Order_Number INT NOT NULL PRIMARY KEY AUTOINCREMENT, | |
Date_of_Order DATE, | |
Paid BOOLEAN DEFAULT false, | |
Delivery_ID INT, | |
Sandwich_Code INT, | |
Quantity INT DEFAULT 0, | |
Subtotal NUMERIC(5,2) | |
FOREIGN KEY(Delivery_ID) REFERENCES Deliveries(Delivery_ID), | |
FOREIGN KEY(Sandwich_Code) REFERENCES Sandwiches(Sandwich_Code) | |
); | |
CREATE TABLE Shops( | |
Shop_ID INT NOT NULL PRIMARY KEY AUTOINCREMENT, | |
Shop_Address_ID INT FOREIGN KEY REFERENCES Addresses(Address_ID) | |
); | |
CREATE TABLE Staff( | |
Staff_ID INT NOT NULL PRIMARY KEY AUTOINCREMENT, | |
Staff_Name VARCHAR(50), | |
Shop_ID INT FOREIGN KEY REFERENCES Shops(Shop_ID) | |
); | |
CREATE TABLE Deliveries( | |
Delivery_ID INT NOT NULL PRIMARY KEY AUTOINCREMENT, | |
Delivery_Date_Time DATE, | |
Customer_ID INT FOREIGN KEY REFERENCES Customers(Customer_ID), | |
Total NUMERIC(5,2), | |
Staff_ID INT FOREIGN KEY REFERENCES Staff(Staff_ID) | |
); | |
CREATE TABLE Customers( | |
Customer_ID INT NOT NULL PRIMARY KEY AUTOINCREMENT, | |
First_Name VARCHAR(25), | |
Last_Name VARCHAR(25), | |
Customer_Address INT FOREIGN KEY REFERENCES Addresses(Address_ID), | |
Phone_Number VARCHAR(16) | |
); | |
CREATE TABLE Sandwiches( | |
Sandwich_Code INT NOT NULL PRIMARY KEY AUTOINCREMENT, | |
Description VARCHAR(160), | |
Price NUMERIC(5,2) | |
); | |
CREATE TABLE Addresses( | |
Address_ID INT NOT NULL PRIMARY KEY AUTOINCREMENT, | |
Line_1 VARCHAR(50), | |
Line_2 VARCHAR(50), | |
Postcode VARCHAR(10) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment