-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSQL Script - SuperTaste Pizza.sql
242 lines (217 loc) · 5.92 KB
/
SQL Script - SuperTaste Pizza.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
DROP TABLE QIngredientHas2Order
DROP TABLE IngredientOrder
DROP TABLE QMenuIngredient
DROP TABLE Ingredient
DROP TABLE QMenuOrder
DROP TABLE MenuItem
DROP TABLE Pickup
DROP TABLE Delivery
DROP TABLE InStoreShift
DROP TABLE DriverShift
DROP TABLE InStorePay
DROP TABLE DriverPay
DROP TABLE PhoneOrder
DROP TABLE WalkInOrder
DROP TABLE Orders
DROP TABLE OrderPayment
DROP TABLE InStoreStaff
DROP TABLE DriverStaff
DROP TABLE BankDetails
DROP TABLE CPhone
DROP TABLE Customer
CREATE TABLE Customer (
CustomerID CHAR(10) PRIMARY KEY,
FirstName VARCHAR(15),
LastName VARCHAR(15),
Street VARCHAR(15),
City VARCHAR(15),
PostCode CHAR(4),
CustomerStatus VARCHAR(10) DEFAULT 'unverified',
CHECK(CustomerStatus IN ('verified', 'unverified')),
)
go
CREATE TABLE Cphone (
PhoneNo CHAR(10) PRIMARY KEY,
CustomerID CHAR(10),
FOREIGN KEY(CustomerID) REFERENCES Customer(CustomerID) ON UPDATE CASCADE ON DELETE CASCADE,
)
go
CREATE TABLE BankDetails (
BankCode CHAR(6) PRIMARY KEY,
BankName VARCHAR(15),
)
go
CREATE TABLE DriverStaff (
StaffID CHAR(10) PRIMARY KEY,
FirstName VARCHAR(15),
LastName VARCHAR(15),
Street VARCHAR(15),
City VARCHAR(15),
Postcode CHAR(4),
TaxFileNo CHAR(9) NOT NULL,
BankCode CHAR(6) NOT NULL,
AccNo VARCHAR(10),
StaffStatus VARCHAR(10) DEFAULT 'Driver',
PaymentRate FLOAT,
LicenceNo CHAR(10) NOT NULL,
Description VARCHAR(30),
FOREIGN KEY(BankCode) REFERENCES BankDetails(BankCode) ON UPDATE CASCADE ON DELETE CASCADE,
)
go
CREATE TABLE InStoreStaff (
StaffID CHAR(10) PRIMARY KEY,
FirstName VARCHAR(15),
LastName VARCHAR(15),
Street VARCHAR(15),
City VARCHAR(15),
Postcode CHAR(4),
TaxFileNo CHAR(9) NOT NULL,
BankCode CHAR(6) NOT NULL,
AccNo VARCHAR(10),
StaffStatus VARCHAR(10) DEFAULT 'In-Store',
PaymentRate FLOAT,
Description VARCHAR(30),
FOREIGN KEY(BankCode) REFERENCES BankDetails(BankCode) ON UPDATE CASCADE ON DELETE CASCADE,
)
go
CREATE TABLE OrderPayment (
PaymentApprovalNo CHAR(8) PRIMARY KEY,
PaymentMethod VARCHAR(15),
TotalAmount FLOAT,
)
go
CREATE TABLE Orders (
OrderNo CHAR(10) PRIMARY KEY,
StaffID CHAR(10) NOT NULL,
CustomerID CHAR(10) NOT NULL,
OrderDateTime DATETIME2,
OrderTaken VARCHAR(10),
OrderType VARCHAR(10),
PaymentApprovalNo CHAR(8) NOT NULL,
Status VARCHAR(10),
FOREIGN KEY(StaffID) REFERENCES InStoreStaff(StaffID) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY(CustomerID) REFERENCES Customer(CustomerID) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY(PaymentApprovalNo) REFERENCES OrderPayment(PaymentApprovalNo) ON UPDATE CASCADE ON DELETE CASCADE,
)
go
CREATE TABLE WalkInOrder (
OrderNo CHAR(10) PRIMARY KEY,
WalkInTime DATETIME2,
FOREIGN KEY(OrderNo) REFERENCES Orders(OrderNo) ON UPDATE CASCADE ON DELETE NO ACTION,
)
go
CREATE TABLE PhoneOrder (
OrderNo CHAR(10) PRIMARY KEY,
PhoneStarted DATETIME2,
PhoneEnded DATETIME2,
FOREIGN KEY(OrderNo) REFERENCES Orders(OrderNo) ON UPDATE CASCADE ON DELETE NO ACTION,
)
go
CREATE TABLE DriverPay (
SalaryID CHAR(10) PRIMARY KEY,
GrossSalary FLOAT,
TaxWithheld FLOAT,
TotalSalary FLOAT,
SalaryStartDate DATE,
SalaryEndDate DATE,
)
go
CREATE TABLE InStorePay (
SalaryID CHAR(10) PRIMARY KEY,
GrossSalary FLOAT,
TaxWithheld FLOAT,
TotalSalary FLOAT,
SalaryStartDate DATE,
SalaryEndDate DATE,
)
go
CREATE TABLE DriverShift (
ShiftID CHAR(5) PRIMARY KEY,
StaffID CHAR(10) NOT NULL,
SalaryID CHAR(10) NOT NULL,
StartDateTime DATETIME2,
EndDateTime DATETIME2,
ShiftType VARCHAR(10) DEFAULT 'Full Time',
FOREIGN KEY (StaffID) REFERENCES DriverStaff(StaffID) ON UPDATE CASCADE ON DELETE NO ACTION,
FOREIGN KEY (SalaryID) REFERENCES DriverPay(SalaryID) ON UPDATE CASCADE ON DELETE NO ACTION,
)
go
CREATE TABLE InStoreShift (
ShiftID CHAR(5) PRIMARY KEY,
StaffID CHAR(10),
SalaryID CHAR(10),
StartDateTime DATETIME2,
EndDateTime DATETIME2,
ShiftType VARCHAR(10) DEFAULT 'Full Time',
FOREIGN KEY (StaffID) REFERENCES InStoreStaff(StaffID) ON UPDATE CASCADE ON DELETE NO ACTION,
FOREIGN KEY (SalaryID) REFERENCES InStorePay(SalaryID) ON UPDATE CASCADE ON DELETE NO ACTION,
)
go
CREATE TABLE Delivery (
OrderNo CHAR(10) PRIMARY KEY,
DeliveryTime DATETIME2,
FOREIGN KEY (OrderNo) REFERENCES PhoneOrder (OrderNo) ON UPDATE CASCADE ON DELETE NO ACTION,
)
go
CREATE TABLE Pickup (
OrderNo CHAR(10) PRIMARY KEY,
PickupTime TIME,
FOREIGN KEY (OrderNo) REFERENCES PhoneOrder (OrderNo) ON UPDATE CASCADE ON DELETE NO ACTION,
)
go
CREATE TABLE MenuItem (
ItemCode CHAR(5) PRIMARY KEY,
ItemName VARCHAR(20),
ItemSize INT,
Description VARCHAR(30),
ItemPrice FLOAT,
)
go
CREATE TABLE QMenuOrder (
OrderNo CHAR(10),
ItemCode CHAR(5),
Quantity INT,
PRIMARY KEY (OrderNo, ItemCode),
FOREIGN KEY (OrderNo) REFERENCES Orders(OrderNo) ON UPDATE CASCADE ON DELETE NO ACTION,
FOREIGN KEY (ItemCode) REFERENCES MenuItem(ItemCode) ON UPDATE CASCADE ON DELETE NO ACTION,
)
go
CREATE TABLE Ingredient (
IngCode CHAR(10) PRIMARY KEY,
IngName VARCHAR(15),
IngSize INT,
IngType VARCHAR(10),
Description VARCHAR(30),
StockLevel INT,
StockTakeDate DATETIME2,
SuggestedStockLevel INT,
ReorderLevel INT,
)
go
CREATE TABLE QMenuIngredient (
ItemCode CHAR(5),
IngCode CHAR(10),
Quantity INT,
PRIMARY KEY (ItemCode,IngCode),
FOREIGN KEY (ItemCode) REFERENCES MenuItem (ItemCode) ON UPDATE CASCADE ON DELETE NO ACTION,
FOREIGN KEY (IngCode) REFERENCES Ingredient (IngCode) ON UPDATE CASCADE ON DELETE NO ACTION,
)
go
CREATE TABLE IngredientOrder (
IngOrderNo CHAR(10) PRIMARY KEY,
IngOrderDate DATE,
ReceivedDate DATE,
TotalAmount FLOAT,
Status VARCHAR(10),
)
go
CREATE TABLE QIngredientHas2Order (
IngCode CHAR(10),
IngOrderNo CHAR(10),
Price FLOAT,
Quantity INT,
PRIMARY KEY (IngCode, IngOrderNo),
FOREIGN KEY (IngCode) REFERENCES Ingredient (IngCode) ON UPDATE CASCADE ON DELETE NO ACTION,
FOREIGN KEY (IngOrderNo) REFERENCES IngredientOrder (IngOrderNo) ON UPDATE CASCADE ON DELETE NO ACTION,
)
go