-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateTables.sql
115 lines (102 loc) · 3.05 KB
/
CreateTables.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
-- Swapnil Mukherjee, Apurva Ratnaparkhi
DROP SCHEMA IF EXISTS Pizzeria;
CREATE SCHEMA Pizzeria;
USE Pizzeria;
CREATE TABLE customer (
CustomerID INT AUTO_INCREMENT PRIMARY KEY,
CustomerFirstName VARCHAR(255) NOT NULL,
CustomerLastName VARCHAR(255) NOT NULL,
CustomerPhone VARCHAR(20),
CustomerStreetName VARCHAR(255),
CustomerCity VARCHAR(100),
CustomerState VARCHAR(100),
CustomerZipCode VARCHAR(20)
);
CREATE TABLE discount (
DiscountID INT AUTO_INCREMENT PRIMARY KEY,
DiscountName VARCHAR(255) NOT NULL,
DiscountType VARCHAR(50) NOT NULL,
DiscountPercentage DECIMAL(5, 2),
DiscountAmount DECIMAL(5, 2)
);
CREATE TABLE pizzaattributes (
PizzaAttributesID INT AUTO_INCREMENT PRIMARY KEY,
Size VARCHAR(50) NOT NULL,
Crust VARCHAR(50) NOT NULL,
Price DECIMAL(5, 2) NOT NULL,
Cost DECIMAL(5, 2) NOT NULL
);
CREATE TABLE orders (
OrderID INT AUTO_INCREMENT PRIMARY KEY,
CustomerID INT,
OrderTime TIME NOT NULL,
OrderStatus VARCHAR(50) NOT NULL,
OrderDate DATE NOT NULL,
OrderType VARCHAR(50) NOT NULL,
OrderCost DECIMAL(5, 2),
OrderPrice DECIMAL(5, 2),
FOREIGN KEY (CustomerID) REFERENCES customer(CustomerID)
);
CREATE TABLE pizza (
PizzaID INT AUTO_INCREMENT PRIMARY KEY,
OrderID INT,
PizzaAttributesID INT,
PizzaPrice DECIMAL(5, 2) NOT NULL,
PizzaCost DECIMAL(5, 2) NOT NULL,
FOREIGN KEY (OrderID) REFERENCES orders(OrderID),
FOREIGN KEY (PizzaAttributesID) REFERENCES pizzaattributes(PizzaAttributesID)
);
CREATE TABLE topping (
ToppingID INT AUTO_INCREMENT PRIMARY KEY,
ToppingName VARCHAR(100) NOT NULL,
ToppingPricePerUnit DECIMAL(4, 2) NOT NULL,
ToppingCostPerUnit DECIMAL(4, 2) NOT NULL,
ToppingInventory INT NOT NULL,
ToppingInventoryMinimum INT NOT NULL,
ToppingSmall DECIMAL(3, 2) NOT NULL,
ToppingMedium DECIMAL(3, 2) NOT NULL,
ToppingLarge DECIMAL(3, 2) NOT NULL,
ToppingExtraLarge DECIMAL(3, 2) NOT NULL
);
CREATE TABLE pizzatopping (
PizzaID INT,
ToppingID INT,
PizzaToppingAdditional BOOLEAN NOT NULL,
PRIMARY KEY (PizzaID, ToppingID),
FOREIGN KEY (PizzaID) REFERENCES pizza(PizzaID),
FOREIGN KEY (ToppingID) REFERENCES topping(ToppingID)
);
CREATE TABLE orderdiscount (
OrderID INT,
DiscountID INT,
PRIMARY KEY (OrderID, DiscountID),
FOREIGN KEY (OrderID) REFERENCES orders(OrderID),
FOREIGN KEY (DiscountID) REFERENCES discount(DiscountID)
);
CREATE TABLE pizzadiscount (
PizzaID INT,
DiscountID INT,
PRIMARY KEY (PizzaID, DiscountID),
FOREIGN KEY (PizzaID) REFERENCES pizza(PizzaID),
FOREIGN KEY (DiscountID) REFERENCES discount(DiscountID)
);
CREATE TABLE pickup (
OrderID INT,
CustomerID INT,
PRIMARY KEY (OrderID),
FOREIGN KEY (OrderID) REFERENCES orders(OrderID),
FOREIGN KEY (CustomerID) REFERENCES customer(CustomerID)
);
CREATE TABLE delivery (
OrderID INT,
CustomerID INT,
PRIMARY KEY (OrderID),
FOREIGN KEY (OrderID) REFERENCES orders(OrderID),
FOREIGN KEY (CustomerID) REFERENCES customer(CustomerID)
);
CREATE TABLE dinein (
OrderID INT,
TableNumber INT,
PRIMARY KEY (OrderID),
FOREIGN KEY (OrderID) REFERENCES orders(OrderID)
);