Repository navigation
Expand file tree
/
Copy pathFINAL_SCRIPT.sql
More file actions
565 lines (545 loc) · 42.3 KB
/
Copy pathFINAL_SCRIPT.sql
File metadata and controls
565 lines (545 loc) · 42.3 KB
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
DROP VIEW customer_age;
DROP VIEW employee_average_ratings;
DROP VIEW store_average_ratings;
DROP TABLE Payment CASCADE CONSTRAINTS;
DROP TABLE Voucher CASCADE CONSTRAINTS;
DROP TABLE Delivery CASCADE CONSTRAINTS;
DROP TABLE Order_Line CASCADE CONSTRAINTS;
DROP TABLE Orders CASCADE CONSTRAINTS;
DROP TABLE Rating CASCADE CONSTRAINTS;
DROP TABLE Stores CASCADE CONSTRAINTS;
DROP TABLE Employee CASCADE CONSTRAINTS;
DROP TABLE Customer CASCADE CONSTRAINTS;
/*Customer Table Creation*/
CREATE TABLE Customer(
CUSTOMER_ID INT PRIMARY KEY,
FIRST_NAME VARCHAR2(30),
LAST_NAME VARCHAR2(30),
DOB DATE,
CLOCATION VARCHAR2(1000),
PHONE_NUMBER VARCHAR2(15),
CONSTRAINT chk_phone_number CHECK (phone_number not like '%[^0-9]%')
);
/*Customer Table Data*/
INSERT INTO Customer VALUES(111,'Ashley','Lee','01-JAN-1999', '34, Persiaran Subang, Taman Indah Subang Uep, 47619 Subang Jaya, Selangor, Malaysia', '011-111-1111');
INSERT INTO Customer VALUES(123,'Jason','Yu','02-JUN-2002', 'Unit 14-5A, Persiaran CapSquare, Off Jalan Munshi Abdullah, Kuala Lumpur, Malaysia', '+60127894888');
INSERT INTO Customer VALUES(516,'Ali','Ahsan','16-JUL-2010', '23,Avila Terrace117 Mariam Way, Singapore', '0164326789');
INSERT INTO Customer VALUES(333,'Muthu','Segaran','23-MAY-1994', '2,Sembawang Hills Estate10 Nemesu Avenue,Singapore', '0145678901');
INSERT INTO Customer VALUES(888,'Marcus','Tan','08-AUG-2008', 'Jalan Galloway, Casa Residency Condominium KL, Bukit Bintang, 50150 Kuala Lumpur, Malaysia', '0188888888');
INSERT INTO Customer VALUES(666,'Jody','Yu','01-DEC-1971', 'The Straits View Condominium, Jalan Permas Selatan, Bandar Baru Permas, 81750 Masai, Selangor, Malaysia', '0151689532');
INSERT INTO Customer VALUES(456,'Aly','Kew','17-APR-1999', 'Jalan Lompat Tinggi, Pangsapuri Servis Sri Acappella, Seksyen 13, 40100 Shah Alam, Selangor, Malaysia', '013-4567897');
INSERT INTO Customer VALUES(222,'John','Doe','13-JAN-2003', 'Axiata Tower, Level 20, 9, Jalan Stesen Sentral 5, Kuala Lumpur, Malaysia', '012787908');
INSERT INTO Customer VALUES(444,'Alex','Tan','14-JUL-1990', 'Sentral, 50470 Kuala Lumpur, Federal Territory of Kuala Lumpur, Malaysia', '0135668808');
INSERT INTO Customer VALUES(777,'Daniel','Amin','01-JUL-1990', 'Level 34, Menara Telekom, Jalan Pantai Baru, 59200 Kuala Lumpur, Malaysia', '0127894889');
INSERT INTO Customer VALUES(478,'Muhammad','Aqeel','01-JAN-1990', 'Level 10, 1 Sentral, Jalan Rakyat, Kuala Lumpur Sentral, 50706 Kuala Lumpur, Wilayah Persekutuan Kuala Lumpur, Malaysia', '0197894889');
INSERT INTO Customer VALUES(235,'Ashley','Lee','01-JAN-1990', '78, Persiaran Greentown 7, Pusat Perdagangan Greentown, 30649 Ipoh, Perak, Malaysia', '0192894889');
INSERT INTO Customer VALUES(457,'Justin','Yu','01-JAN-1956', '85, Lorong Bukit Juru, Taman Bukit Juru, 12732 Simpang Ampat, Pulau Pinang, Malaysia', '0192394889');
INSERT INTO Customer VALUES(883,'Muhammad','Zahar','11-OCT-1989', '99, Jalan Imbi, Imbi, 51783 Kuala Lumpur, Wilayah Persekutuan Kuala Lumpur, Malaysia', '0122222222');
INSERT INTO Customer VALUES(886,'Laura','McKinsey','11-OCT-2000', '64, Lebuh Pasar, George Town, 10118 George Town, Pulau Pinang, Malaysia', '0122222223');
INSERT INTO Customer VALUES(432,'Ashley','McKinsey','11-OCT-2000', '94, Lebuh Presgrave, 10861 George Town, Pulau Pinang, Malaysia', '0122222224');
INSERT INTO Customer VALUES(189,'Muhammad','Arif','21-OCT-2000', '13, Jalan Medan Midah, Taman Midah, 53148 Kuala Lumpur, Wilayah Persekutuan Kuala Lumpur, Malaysia', '0122222225');
INSERT INTO Customer VALUES(790,'Muhammad','Areef','31-AUG-2000', '46, Jalan, Taman Midah, 58215 Kuala Lumpur, Wilayah Persekutuan Kuala Lumpur, Malaysia', '0122222226');
INSERT INTO Customer VALUES(1111,'Jessica','Yu','31-AUG-2004', '46, Jalan Dato Keramat, 10264 George Town, Pulau Pinang, Malaysia', '0122222227');
INSERT INTO Customer VALUES(2222,'Emily','Lee','31-AUG-2010', '54, Persiaran Tasik, Seksyen {no2}, 40501 Shah Alam, Selangor, Malaysia', '0122222228');
INSERT INTO Customer VALUES(3333,'Sofia','Lee','01-AUG-2010', '25, Lebuh Pasar, George Town, 10801 George Town, Pulau Pinang, Malaysia', '0122222229');
INSERT INTO Customer VALUES(4444,'Justin','Tan','01-JUL-2010', '2, Persiaran Subang, Taman Indah Subang Uep, 47628 Subang Jaya, Selangor, Malaysia', '0122222230');
INSERT INTO Customer VALUES(5555,'Joshua','Tan','05-JUL-2010', '38, Jalan Burma, 10734 George Town, Pulau Pinang, Malaysia', '0122222231');
INSERT INTO Customer VALUES(5166,'Joshua','Lee','05-JUL-2006', '17, Jalan Residensi, 10918 George Town, Pulau Pinang, Malaysia', '0122222232');
INSERT INTO Customer VALUES(7777,'Brodi','Tan','05-APR-2006', '62, Lebuh Presgrave, 10608 George Town, Pulau Pinang, Malaysia', '0122222233');
INSERT INTO Customer VALUES(8888,'Milly','Joseph','23-APR-2010', '39, Tingkat Kerjasama, Bukit Tengah, 15639 Bukit Mertajam, Penang, Malaysia', '012-2222234');
INSERT INTO Customer VALUES(9999,'Alexander','Joseph','23-NOV-1999', '74, Tingkat Kerjasama, Bukit Tengah, 19065 Bukit Mertajam, Penang, Malaysia', '0122222235');
INSERT INTO Customer VALUES(1234,'Lana','Joseph','23-NOV-1999', '97, Jln Tun Razak, Kuala Lumpur, 54712 Kuala Lumpur, Wilayah Persekutuan Kuala Lumpur, Malaysia', '0122222236');
INSERT INTO Customer VALUES(3245,'Joseph','Lee','18-NOV-1999', '20, Persiaran Greentown 7, Pusat Perdagangan Greentown, 30107 Ipoh, Perak, Malaysia', '0122222237');
INSERT INTO Customer VALUES(4578,'Alex','Tew','18-NOV-1999', '58, Jalan Cengkeh, Taman Cheras, 56465 Cheras, Wilayah Persekutuan Kuala Lumpur, Malaysia', '0122222238');
INSERT INTO Customer VALUES(4908,'Alex','Lee','18-NOV-1999', '42, Jalan Kelab Golf, 30848 Ipoh, Perak, Malaysia', '012-2222239');
INSERT INTO Customer VALUES(2455,'Jake','Lee','18-NOV-1999', '84, Lebuh Kimberley, George Town, 1099 George Town, Pulau Pinang, Malaysia', '0122222240');
INSERT INTO Customer VALUES(3675,'Jay','Lee','28-FEB-2000', '14, Persiaran Kewajipan, 47645 Subang Jaya, Selangor, Malaysia', '0122222241');
INSERT INTO Customer VALUES(3505,'Natasha','Maxim','28-FEB-2000', '10, Jln Tun Razak, Taman U Thant, 57544 Kuala Lumpur, Wilayah Persekutuan Kuala Lumpur, Malaysia', '0122222242');
INSERT INTO Customer VALUES(3655,'Natalie','Lee','28-SEP-2000', '22, Jalan Burma, 10756 George Town, Pulau Pinang, Malaysia', '0122222243');
INSERT INTO Customer VALUES(3005,'Joey','Lee','28-SEP-2000', '50, Persiaran Medini Utara 3, Bandar, 79641 Nusajaya, Johor, Malaysia', '0122222244');
INSERT INTO Customer VALUES(3000,'Jo Ee','Kew','18-SEP-2010', '9, Jalan Datuk Yeoh Cheng Lee, Kampung Jawa, 30144 Ipoh, Perak, Malaysia', '60122222245');
INSERT INTO Customer VALUES(1005,'Nora','Lee','18-SEP-2010', '23, Jalan Raja Dihilir, 30761 Ipoh, Perak, Malaysia', '012-2222246');
INSERT INTO Customer VALUES(1001,'Nur','Aisha','19-SEP-2008', '88, Jalan Ampang, Kuala Lumpur, 570 Kuala Lumpur, Wilayah Persekutuan Kuala Lumpur, Malaysia', '0122222248');
INSERT INTO Customer VALUES(1002,'Nur','Salma','19-SEP-2006', '43, Persiaran Layar Perak, 7939 Nusajaya, Johor, Malaysia', '0122222249');
INSERT INTO Customer VALUES(1003,'Mary','Wong','10-OCT-1989', '36, Lorong Baru, 1072 George Town, Pulau Pinang, Malaysia', '0122222250');
INSERT INTO Customer VALUES(1004,'Mary','Johnson','29-JUN-1990', '58, Jalan Raja Dihilir, 30128 Ipoh, Perak, Malaysia', '0122222251');
INSERT INTO Customer VALUES(1006,'Nur','Soraya','19-OCT-1978', '6, Tingkat Kerjasama, Bukit Tengah, 12055 Bukit Mertajam, Penang, Malaysia', '0122222252');
INSERT INTO Customer VALUES(1007,'Nur','Norma','18-JUN-1999', '59, Persiaran Subang, Taman Indah Subang Uep, 47611 Subang Jaya, Selangor, Malaysia', '0122222253');
INSERT INTO Customer VALUES(1008,'Mary','Fellon','17-AUG-1998', '11, Jalan Raja Permaisuri Bainun, Taman Mansion, 30842 Ipoh, Perak, Malaysia', '0122222254');
INSERT INTO Customer VALUES(1009,'Ali','Ahad','16-JUN-1979', '31, Changkat Bukit Bintang, Bukit Bintang, 57642 Kuala Lumpur, Wilayah Persekutuan Kuala Lumpur, Malaysia', '0122222255');
INSERT INTO Customer VALUES(1010,'Nur','Salma','12-DEC-2002', '44, Jalan Singa, Seksyen {no2}, 40265 Shah Alam, Selangor, Malaysia', '0122222256');
INSERT INTO Customer VALUES(1011,'Paul','Kim','31-AUG-1978', '44, Jalan Singa, Seksyen {no2}, 40265 Shah Alam, Selangor, Malaysia', '0122222257');
INSERT INTO Customer VALUES(1012,'Joy','Lee','23-JUN-2002', '73, Jalan, Taman Bukit Hijau, 51158 Kuala Lumpur, Wilayah Persekutuan Kuala Lumpur, Malaysia', '0122222258');
INSERT INTO Customer VALUES(1013,'Joy','Teow','12-NOV-2010', '28, Jln Raja Chulan, Kuala Lumpur, 53237 Kuala Lumpur, Wilayah Persekutuan Kuala Lumpur, Malaysia', '0122222259');
INSERT INTO Customer VALUES(1014,'Peter','Tham','22-JAN-2005', '8,Sennett Estate92 Siang Kuang Avenue,Singapore', '0122222260');
/*Employee Table Creation*/
CREATE TABLE Employee(
EMPLOYEE_ID NVARCHAR2(5) PRIMARY KEY,
EMP_FIRST_NAME VARCHAR2(30),
EMP_LAST_NAME VARCHAR2(230),
EMP_PHONE_NUMBER VARCHAR2(15),
MANAGED_BY NVARCHAR2(5),
POSITION VARCHAR2(20),
SALARY NUMBER(10,2),
CONSTRAINT chk_EMP_phone_number CHECK (EMP_phone_number not like '%[^0-9]%')
);
/*Employee Table Data*/
INSERT INTO Employee VALUES ('A01','Ali','Darish','0125556969','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A02','Naib','Daniell','0133333333','M01','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A03','Naib','Raju','0133333334','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A04','Jade','Lee','0133333335','M02','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A05','John','Doe','0133333336','M03','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A06','Eri','Chan','0133333337','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A07','Ellie','Darish','0133333338','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A08','Allie','Tham','0133333339','M01','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A09','Marie','Wong','0133333340','M02','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A10','Alya','Laila','0133333341','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A11','Gaby','Wong','0133333342','M03','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A12','Izmeer','Muzi','0133333343','M01','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A13','Alya','Wong','0133333344','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A14','Alya','Bahirah','0133333345','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A15','Manny','Wong','0133333346','M02','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A16','Ahmad','Ali','0133333347','M03','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A17','Aliya','Ashraf','0133333348','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A18','Aliya','Azry','0133333349','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A19','Ahmad','Ali','0133333350','M01','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A20','Paul','Kim','0133333351','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A21','Joseph','Kim','0133333352','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A22','Joshua','Lee','0133333353','M02','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A23','Ashley','Theow','0133333354','M03','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A24','Emily','Lau','0133333355','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A25','Laura','Kim','0133333356','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A26','Paula','Chong','0133333357','M01','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A27','Larry','Kim','0133333358','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A28','Nora','Juju','0133333359','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A29','Noora','Lam','0133333360','M02','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A30','Peter','Tan','0133333361','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A31','Daniel','Lam','0133333362','M03','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A32','Larry','Kew','0133333363','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A33','Muthu','Raju','0133333364','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A34','Mikhail','Wan','0133333365','M01','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A35','Aru','San','0133333366','M02','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A36','Ashley','Kimmy','0133333367','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A37','Ali','Kim','0133333368','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A38','Qistina','Kim','0133333369','M03','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A39','Lia','Tan','0133333370','M01','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A40','Ahmad','Kim','0133333371','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A41','Joshua','Kim','0133333372','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A42','Jennie','Kim','0133333373','M02','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A43','Lisa','Tham','0133333374','M03','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A44','Rose','Tan','0133333375','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A45','Jisoo','Kim','0133333376','M01','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A46','Maria','Lee','0133333377','M02','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A47','Lana','Ray','0133333378','M03','Customer Service',3000.0);
INSERT INTO Employee VALUES ('A48','Alia','Kim','0133333379','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A49','Yahya','Moud','0133333380','','Delivery',2000.0);
INSERT INTO Employee VALUES ('A50','Juju','Lee','0133333381','M01','Customer Service',3000.0);
INSERT INTO Employee VALUES ('M01','Aisha','Sofia','013-333-3382','','Manager',20000.0);
INSERT INTO Employee VALUES ('M02','Emily','Teng','+60133333383','','Manager',20000.0);
INSERT INTO Employee VALUES ('M03','Justin','Phang','+6013-333-3384','','Manager',20000.0);
/*Store Table Creation*/
CREATE TABLE Stores(
STORE_ID INT PRIMARY KEY,
STORE_NAME VARCHAR2(200),
STORE_LOCATION VARCHAR2(1000),
AGERES CHAR(3)
);
/*Store Table Data*/
INSERT INTO Stores VALUES (001,'The Fire House', 'Selangor','NO');
INSERT INTO Stores VALUES (002,'The Water House', 'Kuala Lumpur','YES');
INSERT INTO Stores VALUES (003,'McDonalds', 'Selangor','NO');
INSERT INTO Stores VALUES (004,'Burger Queen', 'Selangor','NO');
INSERT INTO Stores VALUES (005,'McDonalds', 'Selangor','NO');
INSERT INTO Stores VALUES (006,'McDonalds', 'Perak','YES');
INSERT INTO Stores VALUES (007,'Burger Queen', 'Pahang','NO');
INSERT INTO Stores VALUES (008,'Burger Queen', 'Sarawak','NO');
INSERT INTO Stores VALUES (009,'Tealive', 'Negeri Sembilan','NO');
INSERT INTO Stores VALUES (010,'Chatime', 'Selangor','NO');
INSERT INTO Stores VALUES (011,'Chatime', 'Kuala Lumpur','NO');
INSERT INTO Stores VALUES (012,'The Water House', 'Selangor','YES');
INSERT INTO Stores VALUES (013,'Roadhouse', 'Selangor','YES');
INSERT INTO Stores VALUES (014,'Chatime', 'Selangor','YES');
INSERT INTO Stores VALUES (015,'The Water House', 'Negeri Sembilan','YES');
INSERT INTO Stores VALUES (016,'Chatime', 'Selangor','NO');
INSERT INTO Stores VALUES (017,'Roadhouse', 'Kuala Lumpur','YES');
INSERT INTO Stores VALUES (018,'Tealive', 'Selangor','NO');
INSERT INTO Stores VALUES (019,'The Water House', 'Perak','YES');
INSERT INTO Stores VALUES (020,'The Fire House', 'Kuala Lumpur','NO');
/*Rating Table Creation*/
CREATE TABLE Rating(
CUSTOMER_ID INT,
STORE_ID INT,
EMPLOYEE_ID NVARCHAR2(5),
STORE_RATING_AMOUNT NUMBER(2,1),
EMP_RATING_AMOUNT NUMBER (2,1),
FOREIGN KEY(CUSTOMER_ID) REFERENCES Customer(CUSTOMER_ID),
FOREIGN KEY(STORE_ID) REFERENCES Stores(STORE_ID),
FOREIGN KEY (EMPLOYEE_ID) REFERENCES Employee(EMPLOYEE_ID),
CONSTRAINT chk_STORE_RATING_AMOUNT CHECK (STORE_RATING_AMOUNT >= 0 AND STORE_RATING_AMOUNT <= 5),
CONSTRAINT chk_EMP_RATING_AMOUNT CHECK (EMP_RATING_AMOUNT >= 0 AND EMP_RATING_AMOUNT <= 5)
);
/*Rating Table Data*/
INSERT INTO Rating VALUES (111, 001, 'A01', 4, 4);
INSERT INTO Rating VALUES (123, 003, 'A02', 2, 2);
INSERT INTO Rating VALUES (516, 001, 'A12', 4, 4);
INSERT INTO Rating VALUES (111, 016, 'A01', 4, 2);
INSERT INTO Rating VALUES (888, 006, 'A49', 4, 5);
INSERT INTO Rating VALUES (888, 006, 'A48', 2, 4);
INSERT INTO Rating VALUES (111, 014, 'A10', 2, 5);
INSERT INTO Rating VALUES (123, 011, 'A02', 2, 4);
INSERT INTO Rating VALUES (888, 006, 'A48', 3, 5);
INSERT INTO Rating VALUES (516, 012, 'A10', 4, 4);
INSERT INTO Rating VALUES (516, 001, 'A12', 2, 3);
INSERT INTO Rating VALUES (1001, 011, 'A17', 2, 2);
INSERT INTO Rating VALUES (123, 003, 'A17', 2, 4);
INSERT INTO Rating VALUES (1001, 017, 'A01', 2, 5);
INSERT INTO Rating VALUES (1001, 017, 'A17', 5, 4);
/*Order Table Creation*/
CREATE TABLE Orders(
ORDER_ID INT PRIMARY KEY,
CUSTOMER_ID INT,
TIME_ORDER_PLACED TIMESTAMP(2),
FOREIGN KEY (CUSTOMER_ID) REFERENCES Customer(CUSTOMER_ID),
CONSTRAINT chk_TIME_ORDER_PLACED CHECK (EXTRACT(HOUR FROM TIME_ORDER_PLACED) >= 9 AND EXTRACT(HOUR FROM TIME_ORDER_PLACED) <= 23)
);
/*Order Table Data*/
INSERT INTO Orders VALUES (100000, 111, TO_TIMESTAMP('01-APR-2021 22:03:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100001, 111, TO_TIMESTAMP('01-JUN-2021 18:03:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100002, 111, TO_TIMESTAMP('01-DEC-2022 14:33:59','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100003, 123, TO_TIMESTAMP('01-NOV-2021 18:48:20','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100004, 123, TO_TIMESTAMP('01-OCT-2022 19:00:20','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100005, 123, TO_TIMESTAMP('11-AUG-2022 18:03:20','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100006, 516, TO_TIMESTAMP('01-JUN-2021 09:00:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100007, 516, TO_TIMESTAMP('01-MAY-2021 09:05:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100008, 516, TO_TIMESTAMP('01-APR-2022 09:00:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100009, 888, TO_TIMESTAMP('01-JUN-2022 11:45:30','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100010, 888, TO_TIMESTAMP('01-JUN-2022 11:00:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100011, 888, TO_TIMESTAMP('12-DEC-2021 20:00:16','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100012, 777, TO_TIMESTAMP('28-DEC-2021 18:11:15','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100013, 777, TO_TIMESTAMP('01-AUG-2021 18:22:23','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100014, 777, TO_TIMESTAMP('16-SEP-2022 13:40:22','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100015, 222, TO_TIMESTAMP('13-FEB-2022 09:00:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100016, 222, TO_TIMESTAMP('17-JUL-2022 09:05:45','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100017, 222, TO_TIMESTAMP('18-SEP-2022 21:00:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100018, 444, TO_TIMESTAMP('17-AUG-2022 09:23:59','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100019, 444, TO_TIMESTAMP('29-NOV-2021 13:09:10','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100020, 444, TO_TIMESTAMP('17-JUL-2022 19:24:25','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100021, 478, TO_TIMESTAMP('19-NOV-2021 17:00:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100022, 235, TO_TIMESTAMP('17-JUL-2022 09:07:35','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100023, 883, TO_TIMESTAMP('07-JAN-2022 13:23:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100024, 883, TO_TIMESTAMP('07-FEB-2022 10:38:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100025, 886, TO_TIMESTAMP('27-AUG-2021 09:33:49','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100026, 886, TO_TIMESTAMP('17-MAR-2021 15:21:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100027, 886, TO_TIMESTAMP('13-JUN-2022 21:00:39','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100028, 432, TO_TIMESTAMP('11-JAN-2022 14:22:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100029, 1111, TO_TIMESTAMP('17-JUL-2022 09:45:29','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100030, 1001, TO_TIMESTAMP('15-JUN-2022 17:39:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100031, 1111, TO_TIMESTAMP('09-JAN-2021 15:04:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100032, 1005, TO_TIMESTAMP('27-DEC-2021 20:20:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100033, 1111, TO_TIMESTAMP('09-FEB-2022 16:49:04','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100034, 7777, TO_TIMESTAMP('15-JAN-2021 09:49:47','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100035, 7777, TO_TIMESTAMP('04-NOV-2022 09:03:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100036, 8888, TO_TIMESTAMP('23-JUN-2022 12:00:02','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100037, 3333, TO_TIMESTAMP('01-MAR-2021 13:34:34','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100038, 7777, TO_TIMESTAMP('19-APR-2021 15:01:22','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100039, 8888, TO_TIMESTAMP('18-DEC-2022 16:26:00','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100040, 7777, TO_TIMESTAMP('17-JUL-2022 11:09:56','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100041, 9999, TO_TIMESTAMP('13-AUG-2022 18:13:11','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100042, 9999, TO_TIMESTAMP('20-OCT-2021 17:05:47','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100043, 9999, TO_TIMESTAMP('09-OCT-2022 13:24:27','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100044, 9999, TO_TIMESTAMP('19-OCT-2022 13:24:27','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100045, 2455, TO_TIMESTAMP('22-NOV-2022 21:57:30','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100046, 3675, TO_TIMESTAMP('13-JUL-2021 14:00:04','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100047, 3505, TO_TIMESTAMP('11-OCT-2022 19:46:12','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100048, 3505, TO_TIMESTAMP('27-FEB-2022 21:22:33','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO Orders VALUES (100049, 1001, TO_TIMESTAMP('10-NOV-2021 19:06:02','DD-MON-YYYY HH24:MI:SS'));
CREATE TABLE Order_line(
ORDER_ID INT,
STORE_ID INT,
PRODUCT_ID INT,
PRODUCT VARCHAR2 (100),
QUANTITY NUMBER (3),
PRICE DECIMAL (10,2),
PRIMARY KEY (ORDER_ID, STORE_ID, PRODUCT_ID),
FOREIGN KEY (ORDER_ID) REFERENCES Orders(ORDER_ID),
FOREIGN KEY (STORE_ID) REFERENCES Stores(STORE_ID),
CONSTRAINT chk_QUANTITY CHECK (QUANTITY > 0)
);
/*Order_Line Table Data*/
INSERT INTO Order_Line Values (100000,001,008,'Hot_Steak',2,120.0);
INSERT INTO Order_Line Values (100000,001,012,'Bangers_and_Mash',2,40.0);
INSERT INTO Order_Line Values (100000,001,002,'Kids_Steak',1,20.0);
INSERT INTO Order_Line Values (100001,003,001,'Wagyu_Steak',1,100.0);
INSERT INTO Order_Line Values (100002,004,031,'Chicken_Sandwich',5,80.0);
INSERT INTO Order_Line Values (100002,004,003,'Pork_Chops',1,25.0);
INSERT INTO Order_Line Values (100003,002,017,'Ceasar_Salad',2,30.0);
INSERT INTO Order_Line Values (100003,002,001,'Soup_of_the_Day',3,60.0);
INSERT INTO Order_Line Values (100004,011,002,'Milk_Tea_Basic',2,20.0);
INSERT INTO Order_Line Values (100005,017,011,'Aglio_e_olio',2,60.0);
INSERT INTO Order_Line Values (100006,018,003,'Milo_Boba',2,30.0);
INSERT INTO Order_Line Values (100006,018,019,'Milk_Shake',2,15.0);
INSERT INTO Order_Line Values (100007,012,001,'DoTD',3,45.0);
INSERT INTO Order_Line Values (100008,010,002,'Milk_Tea_Basic',1,10.0);
INSERT INTO Order_Line Values (100009,019,012,'Watermelon_Shake',1,20.0);
INSERT INTO Order_Line Values (100009,019,003,'Cold_Cappucino',2,30.0);
INSERT INTO Order_Line Values (100009,019,005,'Cold_Latte',2,30.0);
INSERT INTO Order_Line Values (100010,006,007,'Cappucino',2,40.0);
INSERT INTO Order_Line Values (100011,019,011,'Orange_Shake',1,20.0);
INSERT INTO Order_Line Values (100011,019,012,'Watermelon_Shake',2,40.0);
INSERT INTO Order_Line Values (100012,019,012,'Watermelon_Shake',2,40.0);
INSERT INTO Order_Line Values (100013,019,012,'Watermelon_Shake',2,40.0);
INSERT INTO Order_Line Values (100014,019,012,'Watermelon_Shake',2,40.0);
INSERT INTO Order_Line Values (100015,019,012,'Watermelon_Shake',2,40.0);
INSERT INTO Order_Line Values (100016,019,013,'Water',1,100.0);
INSERT INTO Order_Line Values (100016,019,014,'Chili_Steak',1,120.0);
INSERT INTO Order_Line Values (100017,020,001,'Hotpot',1,40.0);
INSERT INTO Order_Line Values (100017,020,013,'Spicy_Fish',1,40.0);
INSERT INTO Order_Line Values (100017,020,012,'Roasted_Chicken',1,63.0);
INSERT INTO Order_Line Values (100017,020,015,'Spicy_Chicken',1,50.0);
INSERT INTO Order_Line Values (100018,015,014,'Ice_Water',1,120.0);
INSERT INTO Order_Line Values (100018,015,066,'Vodka',1,30.0);
INSERT INTO Order_Line Values (100018,015,003,'Orange_juice',1,7.0);
INSERT INTO Order_Line Values (100019,007,014,'Beef_Burger',1,24.0);
INSERT INTO Order_Line Values (100020,010,014,'Milk_Tea',1,10.0);
INSERT INTO Order_Line Values (100020,010,015,'Caramel_Milk_Tea',1,18.0);
INSERT INTO Order_Line Values (100021,003,013,'Fish_Burger',1,18.0);
INSERT INTO Order_Line Values (100021,003,014,'Mc_Chickne',1,23.0);
INSERT INTO Order_Line Values (100022,014,004,'Milk_Bubble_Tea',1,20.0);
INSERT INTO Order_Line Values (100023,017,004,'Steak',2,29.0);
INSERT INTO Order_Line Values (100023,017,005,'Spaghetti',1,23.0);
INSERT INTO Order_Line Values (100023,017,012,'Coke',2,12.0);
INSERT INTO Order_Line Values (100024,003,013,'Beef_Burger',1,24.0);
INSERT INTO Order_Line Values (100025,010,001,'Caramel_Milk_Tea',2,36.0);
INSERT INTO Order_Line Values (100025,010,002,'Milk_Tea',1,10.0);
INSERT INTO Order_Line Values (100025,010,003,'Bubble_Tea',1,18.0);
INSERT INTO Order_Line Values (100026,010,001,'Caramel_Milk_Tea',2,36.0);
INSERT INTO Order_Line Values (100027,010,001,'Caramel_Milk_Tea',2,36.0);
INSERT INTO Order_Line Values (100028,009,001,'Bubble_Tea_Small',1,15.0);
INSERT INTO Order_Line Values (100028,009,002,'Bubble_Tea_Medium',1,16.0);
INSERT INTO Order_Line Values (100028,009,003,'Bubble_Tea_Large',1,17.0);
INSERT INTO Order_Line Values (100029,005,001,'Coke',1,6.0);
INSERT INTO Order_Line Values (100029,005,012,'Mc_Nugget',1,13.0);
INSERT INTO Order_Line Values (100029,005,009,'Mc_Chicken',1,22.0);
INSERT INTO Order_Line Values (100030,005,009,'Mc_Chicken',1,22.0);
INSERT INTO Order_Line Values (100031,005,009,'Mc_Chicken',1,22.0);
INSERT INTO Order_Line Values (100032,005,009,'Mc_Chicken',1,22.0);
INSERT INTO Order_Line Values (100033,005,009,'Mc_Chicken',1,22.0);
INSERT INTO Order_Line Values (100034,005,009,'Mc_Chicken',1,22.0);
INSERT INTO Order_Line Values (100035,013,001,'Steak',1,29.0);
INSERT INTO Order_Line Values (100036,019,005,'Apple_Juice',1,7.0);
INSERT INTO Order_Line Values (100037,019,003,'Orange_Juice',1,7.0);
INSERT INTO Order_Line Values (100038,009,001,'Bubble_Tea_Small',1,15.0);
INSERT INTO Order_Line Values (100039,009,003,'Bubble_Tea_Large',1,17.0);
INSERT INTO Order_Line Values (100040,007,018,'Breakfast_Muffin',2,14.0);
INSERT INTO Order_Line Values (100041,007,018,'Breakfast_Muffin',2,14.0);
INSERT INTO Order_Line Values (100042,007,018,'Breakfast_Muffin',2,14.0);
INSERT INTO Order_Line Values (100043,007,018,'Breakfast_Muffin',2,14.0);
INSERT INTO Order_Line Values (100044,007,018,'Breakfast_Muffin',2,14.0);
INSERT INTO Order_Line Values (100045,001,003,'Hotpot',1,40.0);
INSERT INTO Order_Line Values (100046,001,003,'Hotpot',1,40.0);
INSERT INTO Order_Line Values (100047,001,003,'Hotpot',1,40.0);
INSERT INTO Order_Line Values (100048,001,003,'Hotpot',1,40.0);
INSERT INTO Order_Line Values (100049,001,003,'Hotpot',1,40.0);
/*Delivery Table Creation*/
CREATE TABLE Delivery(
DELIVERY_ID INT,
EMPLOYEE_ID NVARCHAR2(5),
ORDER_ID INT,
ETA TIMESTAMP(2),
DEL_PRICE NUMBER(10,2),
PRIMARY KEY (DELIVERY_ID, EMPLOYEE_ID, ORDER_ID),
FOREIGN KEY (EMPLOYEE_ID) REFERENCES Employee(EMPLOYEE_ID),
FOREIGN KEY (ORDER_ID) REFERENCES Orders(ORDER_ID),
CONSTRAINT chk_DeliveryPrice CHECK (DEL_PRICE >= 5)
);
/*Delivery Table Data*/
INSERT INTO Delivery VALUES (000001, 'A01', 100000, TO_TIMESTAMP('01-APR-2021 22:33:00','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000002, 'A01', 100001, TO_TIMESTAMP('01-JUN-2021 18:33:00','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000003, 'A01', 100002, TO_TIMESTAMP('01-DEC-2022 15:33:59','DD-MON-YYYY HH24:MI:SS'), 10.00);
INSERT INTO Delivery VALUES (000004, 'A03', 100003, TO_TIMESTAMP('01-NOV-2021 19:18:20','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000005, 'A06', 100004, TO_TIMESTAMP('01-OCT-2022 19:30:20','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000006, 'A06', 100005, TO_TIMESTAMP('11-AUG-2022 18:58:20','DD-MON-YYYY HH24:MI:SS'), 8.00);
INSERT INTO Delivery VALUES (000007, 'A07', 100006, TO_TIMESTAMP('01-JUN-2021 09:30:00','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000008, 'A07', 100007, TO_TIMESTAMP('01-MAY-2021 09:35:00','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000009, 'A07', 100008, TO_TIMESTAMP('01-APR-2022 10:10:00','DD-MON-YYYY HH24:MI:SS'), 13.00);
INSERT INTO Delivery VALUES (000010, 'A07', 100009, TO_TIMESTAMP('01-JUN-2022 12:45:30','DD-MON-YYYY HH24:MI:SS'), 10.00);
INSERT INTO Delivery VALUES (000011, 'A17', 100010, TO_TIMESTAMP('01-JUN-2022 11:30:00','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000012, 'A18', 100011, TO_TIMESTAMP('12-DEC-2021 20:45:16','DD-MON-YYYY HH24:MI:SS'), 7.00);
INSERT INTO Delivery VALUES (000013, 'A36', 100012, TO_TIMESTAMP('28-DEC-2021 18:41:15','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000014, 'A42', 100013, TO_TIMESTAMP('01-AUG-2021 18:52:23','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000015, 'A49', 100014, TO_TIMESTAMP('16-SEP-2022 14:40:22','DD-MON-YYYY HH24:MI:SS'), 10.00);
INSERT INTO Delivery VALUES (000016, 'A28', 100015, TO_TIMESTAMP('13-FEB-2022 09:30:00','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000017, 'A21', 100016, TO_TIMESTAMP('17-JUL-2022 09:55:45','DD-MON-YYYY HH24:MI:SS'), 7.00);
INSERT INTO Delivery VALUES (000018, 'A20', 100017, TO_TIMESTAMP('18-SEP-2022 21:30:00','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000019, 'A37', 100018, TO_TIMESTAMP('17-AUG-2022 10:13:59','DD-MON-YYYY HH24:MI:SS'), 8.00);
INSERT INTO Delivery VALUES (000020, 'A41', 100019, TO_TIMESTAMP('29-NOV-2021 13:39:10','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000021, 'A44', 100020, TO_TIMESTAMP('17-JUL-2022 19:54:25','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000022, 'A28', 100021, TO_TIMESTAMP('19-NOV-2021 16:10:00','DD-MON-YYYY HH24:MI:SS'), 12.00);
INSERT INTO Delivery VALUES (000023, 'A06', 100022, TO_TIMESTAMP('17-JUL-2022 09:37:35','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000024, 'A01', 100023, TO_TIMESTAMP('07-JAN-2022 13:53:00','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000025, 'A14', 100024, TO_TIMESTAMP('07-FEB-2022 11:38:00','DD-MON-YYYY HH24:MI:SS'), 10.00);
INSERT INTO Delivery VALUES (000026, 'A17', 100025, TO_TIMESTAMP('27-AUG-2021 10:33:49','DD-MON-YYYY HH24:MI:SS'), 10.00);
INSERT INTO Delivery VALUES (000027, 'A17', 100026, TO_TIMESTAMP('17-MAR-2021 15:51:00','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000028, 'A24', 100027, TO_TIMESTAMP('13-JUN-2022 21:30:39','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000029, 'A28', 100028, TO_TIMESTAMP('11-JAN-2022 14:52:00','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000030, 'A32', 100029, TO_TIMESTAMP('17-JUL-2022 10:25:29','DD-MON-YYYY HH24:MI:SS'), 6.00);
INSERT INTO Delivery VALUES (000031, 'A36', 100030, TO_TIMESTAMP('15-JUN-2022 18:39:00','DD-MON-YYYY HH24:MI:SS'), 10.00);
INSERT INTO Delivery VALUES (000032, 'A07', 100031, TO_TIMESTAMP('09-JAN-2021 15:59:00','DD-MON-YYYY HH24:MI:SS'), 9.00);
INSERT INTO Delivery VALUES (000033, 'A20', 100032, TO_TIMESTAMP('27-DEC-2021 20:50:00','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000034, 'A25', 100033, TO_TIMESTAMP('09-FEB-2022 17:29:04','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000035, 'A33', 100034, TO_TIMESTAMP('15-JAN-2021 10:59:47','DD-MON-YYYY HH24:MI:SS'), 10.00);
INSERT INTO Delivery VALUES (000036, 'A33', 100035, TO_TIMESTAMP('04-NOV-2022 09:33:00','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000037, 'A06', 100036, TO_TIMESTAMP('23-JUN-2022 12:50:02','DD-MON-YYYY HH24:MI:SS'), 7.00);
INSERT INTO Delivery VALUES (000038, 'A40', 100037, TO_TIMESTAMP('01-MAR-2021 14:24:34','DD-MON-YYYY HH24:MI:SS'), 8.00);
INSERT INTO Delivery VALUES (000039, 'A32', 100038, TO_TIMESTAMP('19-APR-2021 15:31:22','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000040, 'A37', 100039, TO_TIMESTAMP('18-DEC-2022 16:56:00','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000041, 'A20', 100040, TO_TIMESTAMP('17-JUL-2022 11:39:56','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000042, 'A49', 100041, TO_TIMESTAMP('13-AUG-2022 18:58:11','DD-MON-YYYY HH24:MI:SS'), 9.00);
INSERT INTO Delivery VALUES (000043, 'A10', 100042, TO_TIMESTAMP('20-OCT-2021 17:45:47','DD-MON-YYYY HH24:MI:SS'), 6.00);
INSERT INTO Delivery VALUES (000044, 'A21', 100043, TO_TIMESTAMP('09-OCT-2022 13:54:27','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000045, 'A17', 100044, TO_TIMESTAMP('19-OCT-2022 13:54:27','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000046, 'A18', 100045, TO_TIMESTAMP('22-NOV-2022 22:57:30','DD-MON-YYYY HH24:MI:SS'), 10.00);
INSERT INTO Delivery VALUES (000047, 'A28', 100046, TO_TIMESTAMP('13-JUL-2021 14:30:04','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000048, 'A32', 100047, TO_TIMESTAMP('11-OCT-2022 20:46:12','DD-MON-YYYY HH24:MI:SS'), 10.00);
INSERT INTO Delivery VALUES (000049, 'A01', 100048, TO_TIMESTAMP('27-FEB-2022 21:52:33','DD-MON-YYYY HH24:MI:SS'), 5.00);
INSERT INTO Delivery VALUES (000050, 'A44', 100049, TO_TIMESTAMP('10-NOV-2021 19:36:02','DD-MON-YYYY HH24:MI:SS'), 5.00);
/*Voucher Table Creation*/
CREATE TABLE Voucher (
VOUCHER_CODE CHAR(5) PRIMARY KEY,
CUSTOMER_ID INT NOT NULL,
EXP_DATE DATE,
REDEEM_DATE DATE,
FOREIGN KEY (CUSTOMER_ID) REFERENCES Customer(CUSTOMER_ID)
);
/*Voucher Table Data*/
INSERT INTO Voucher VALUES ('V0001', 111, '01-APR-2022', '01-JAN-2022');
INSERT INTO Voucher VALUES ('V0002', 123, '15-DEC-2022', '15-SEP-2022');
INSERT INTO Voucher VALUES ('V0003', 516, '04-APR-2022', '04-JAN-2022');
INSERT INTO Voucher VALUES ('V0004', 333, '01-JUL-2022', '01-APR-2022');
INSERT INTO Voucher VALUES ('V0005', 888, '01-APR-2022', '01-JAN-2022');
INSERT INTO Voucher VALUES ('V0006', 235, '05-Dec-2022', '05-Sep-2022');
INSERT INTO Voucher VALUES ('V0007', 456, '02-AUG-2022', '02-AUG-2022');
INSERT INTO Voucher VALUES ('V0008', 222, '11-DEC-2022', '11-SEP-2022');
INSERT INTO Voucher VALUES ('V0009', 444, '02-APR-2022', '02-JAN-2022');
INSERT INTO Voucher VALUES ('V0010', 777, '02-DEC-2022', '02-SEP-2022');
INSERT INTO Voucher VALUES ('V0011', 111, '02-APR-2022', '02-JAN-2022');
INSERT INTO Voucher VALUES ('V0012', 235, '02-AUG-2022', '02-MAY-2022');
INSERT INTO Voucher VALUES ('V0013', 457, '03-AUG-2022', '03-MAY-2022');
INSERT INTO Voucher VALUES ('V0014', 883, '03-NOV-2022', '03-AUG-2022');
INSERT INTO Voucher VALUES ('V0015', 457, '03-APR-2022', '03-JAN-2022');
INSERT INTO Voucher VALUES ('V0016', 883, '03-JUL-2022', '03-APR-2022');
INSERT INTO Voucher VALUES ('V0017', 886, '03-DEC-2022', '03-SEP-2022');
INSERT INTO Voucher VALUES ('V0018', 432, '03-DEC-2022', '03-SEP-2022');
INSERT INTO Voucher VALUES ('V0019', 189, '04-APR-2022', '04-JAN-2022');
INSERT INTO Voucher VALUES ('V0020', 790, '04-APR-2022', '04-JAN-2022');
INSERT INTO Voucher VALUES ('V0021', 1111, '04-DEC-2022', '04-SEP-2022');
INSERT INTO Voucher VALUES ('V0022', 2222, '04-APR-2022', '04-JAN-2022');
INSERT INTO Voucher VALUES ('V0023', 3333, '04-DEC-2022', '04-SEP-2022');
INSERT INTO Voucher VALUES ('V0024', 4444, '04-DEC-2022', '04-Sep-2022');
INSERT INTO Voucher VALUES ('V0025', 5555, '05-APR-2022', '05-JAN-2022');
INSERT INTO Voucher VALUES ('V0026', 5166, '05-APR-2022', '05-JAN-2022');
INSERT INTO Voucher VALUES ('V0027', 7777, '05-JUL-2022', '05-APR-2022');
INSERT INTO Voucher VALUES ('V0028', 235, '05-APR-2022', '05-JAN-2022');
INSERT INTO Voucher VALUES ('V0029', 9999, '05-APR-2022', '05-JAN-2022');
INSERT INTO Voucher VALUES ('V0030', 1234, '05-APR-2022', '06-JAN-2022');
INSERT INTO Voucher VALUES ('V0031', 235, '05-APR-2022', '06-JAN-2022');
INSERT INTO Voucher VALUES ('V0032', 4578, '06-NOV-2022', '06-AUG-2022');
INSERT INTO Voucher VALUES ('V0033', 4908, '06-NOV-2022', '06-AUG-2022');
INSERT INTO Voucher VALUES ('V0034', 2455, '05-APR-2022', '05-JAN-2022');
INSERT INTO Voucher VALUES ('V0035', 3675, '06-SEP-2022', '06-JUN-2022');
INSERT INTO Voucher VALUES ('V0036', 3505, '07-APR-2022', '07-JAN-2022');
INSERT INTO Voucher VALUES ('V0037', 3000, '07-JUN-2022', '07-MAR-2022');
INSERT INTO Voucher VALUES ('V0038', 1005, '07-MAY-2022', '07-FEB-2022');
INSERT INTO Voucher VALUES ('V0039', 1001, '07-JUL-2022', '07-APR-2022');
INSERT INTO Voucher VALUES ('V0040', 1002, '16-APR-2022', '16-JAN-2022');
INSERT INTO Voucher VALUES ('V0041', 1003, '07-SEP-2022', '07-SEP-2022');
INSERT INTO Voucher VALUES ('V0042', 1004, '08-APR-2022', '08-JAN-2022');
INSERT INTO Voucher VALUES ('V0043', 1006, '08-APR-2022', '08-JAN-2022');
INSERT INTO Voucher VALUES ('V0044', 1007, '12-MAY-2022', '12-FEB-2022');
INSERT INTO Voucher VALUES ('V0045', 888, '08-APR-2022', '08-JAN-2022');
INSERT INTO Voucher VALUES ('V0046', 1009, '08-NOV-2022', '08-AUG-2022');
INSERT INTO Voucher VALUES ('V0047', 1010, '08-APR-2022', '08-JAN-2022');
INSERT INTO Voucher VALUES ('V0048', 1011, '30-JUN-2022', '30-MAR-2022');
INSERT INTO Voucher VALUES ('V0049', 1012, '30-APR-2022', '30-JAN-2022');
INSERT INTO Voucher VALUES ('V0050', 1013, '30-DEC-2022', '30-SEP-2022');
INSERT INTO Voucher VALUES ('V0051', 1014, '30-NOV-2022', '30-AUG-2022');
/*Payment Table Creation*/
CREATE TABLE Payment(
CUSTOMER_ID INT,
ORDER_ID INT,
TOTAL NUMBER(10,2), /*del + prod_price*q*/
PRIMARY KEY (CUSTOMER_ID,ORDER_ID),
FOREIGN KEY (CUSTOMER_ID) REFERENCES Customer(CUSTOMER_ID),
FOREIGN KEY (ORDER_ID) REFERENCES Orders (ORDER_ID)
);
/*Payment Table Data*/
INSERT INTO Payment VALUES (111, 100000, 345.00);
INSERT INTO Payment VALUES (111, 100001, 105.00);
INSERT INTO Payment VALUES (111, 100002, 435.00);
INSERT INTO Payment VALUES (123, 100003, 185.00);
INSERT INTO Payment VALUES (123, 100004, 48.00);
INSERT INTO Payment VALUES (123, 100005, 125.00);
INSERT INTO Payment VALUES (516, 100006, 95.00);
INSERT INTO Payment VALUES (516, 100007, 148.00);
INSERT INTO Payment VALUES (516, 100008, 20.00);
INSERT INTO Payment VALUES (888, 100009, 145.00);
INSERT INTO Payment VALUES (888, 100010, 85.00);
INSERT INTO Payment VALUES (888, 100011, 107.00);
INSERT INTO Payment VALUES (777, 100012, 85.00);
INSERT INTO Payment VALUES (777, 100013, 85.00);
INSERT INTO Payment VALUES (777, 100014, 90.00);
INSERT INTO Payment VALUES (222, 100015, 85.00);
INSERT INTO Payment VALUES (222, 100016, 227.00);
INSERT INTO Payment VALUES (222, 100017, 198.00);
INSERT INTO Payment VALUES (444, 100018, 165.00);
INSERT INTO Payment VALUES (444, 100019, 29.00);
INSERT INTO Payment VALUES (444, 100020, 33.00);
INSERT INTO Payment VALUES (478, 100021, 53.00);
INSERT INTO Payment VALUES (235, 100022, 25.00);
INSERT INTO Payment VALUES (883, 100023, 110.00);
INSERT INTO Payment VALUES (883, 100024, 34.00);
INSERT INTO Payment VALUES (886, 100025, 110.00);
INSERT INTO Payment VALUES (886, 100026, 77.00);
INSERT INTO Payment VALUES (886, 100027, 77.00);
INSERT INTO Payment VALUES (432, 100028, 53.00);
INSERT INTO Payment VALUES (1111, 100029, 46.00);
INSERT INTO Payment VALUES (1001, 100030, 32.00);
INSERT INTO Payment VALUES (1111, 100031, 31.00);
INSERT INTO Payment VALUES (1005, 100032, 27.00);
INSERT INTO Payment VALUES (1111, 100033, 27.00);
INSERT INTO Payment VALUES (7777, 100034, 32.00);
INSERT INTO Payment VALUES (7777, 100035, 34.00);
INSERT INTO Payment VALUES (8888, 100036, 14.00);
INSERT INTO Payment VALUES (3333, 100037, 15.00);
INSERT INTO Payment VALUES (7777, 100038, 20.00);
INSERT INTO Payment VALUES (8888, 100039, 22.00);
INSERT INTO Payment VALUES (7777, 100040, 33.00);
INSERT INTO Payment VALUES (9999, 100041, 37.00);
INSERT INTO Payment VALUES (9999, 100042, 34.00);
INSERT INTO Payment VALUES (9999, 100043, 33.00);
INSERT INTO Payment VALUES (9999, 100044, 33.00);
INSERT INTO Payment VALUES (2455, 100045, 50.00);
INSERT INTO Payment VALUES (3675, 100046, 40.00);
INSERT INTO Payment VALUES (3505, 100047, 50.00);
INSERT INTO Payment VALUES (3505, 100048, 45.00);
INSERT INTO Payment VALUES (1001, 100049, 45.00);
/*INDEX AND VIEWS*/
CREATE INDEX CUSTOMER_AGE on CUSTOMER (CUSTOMER_ID, FIRST_NAME, LAST_NAME, DOB);
/*(Index is required for this as customer details, especially date of birth) is needed to calculate the age of the customer to determine the age restriction. Furthermore, customer id is frequently used throughout all the tables, such as orders and delivery table.)*/
CREATE INDEX STORE_RATING on STORES (STORE_ID, STORE_NAME, AGERES);
/*(Index is required to ensure that stores must have an average rating above 1.5 to be applicable for orders)*/
CREATE INDEX EMPLOYEE_RATING on EMPLOYEE (EMPLOYEE_ID, EMP_FIRST_NAME, EMP_LAST_NAME);
/*(Index is required to ensure that employees who are delivering must have ratings above>1.5)*/
CREATE VIEW customer_age AS
SELECT CUSTOMER_ID AS CID, FIRST_NAME, LAST_NAME, (CURRENT_DATE - DOB) AS "Age"
FROM Customer;
CREATE VIEW employee_average_ratings AS
SELECT Employee.EMPLOYEE_ID AS Employee, ROUND((AVG(RATING.EMP_RATING_AMOUNT)),1) AS Rating_Amount
FROM Employee, Rating
WHERE EMPLOYEE.EMPLOYEE_ID = RATING.EMPLOYEE_ID
GROUP BY EMPLOYEE.EMPLOYEE_ID;
CREATE VIEW store_average_ratings AS
SELECT STORES.STORE_ID AS ID, ROUND((AVG (RATING.STORE_RATING_AMOUNT)),1) AS Rating_Amount
FROM Stores, Rating
WHERE Stores.Store_ID = Rating.Store_ID
GROUP BY Stores.Store_ID;