-
Notifications
You must be signed in to change notification settings - Fork 0
/
bakery.sql
354 lines (326 loc) · 17.7 KB
/
bakery.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
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
/*
Navicat Premium Data Transfer
Source Server : localhost81
Source Server Type : MySQL
Source Server Version : 100418
Source Host : localhost:3306
Source Schema : bakery
Target Server Type : MySQL
Target Server Version : 100418
File Encoding : 65001
Date: 27/08/2021 12:04:24
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for banners
-- ----------------------------
DROP TABLE IF EXISTS `banners`;
CREATE TABLE `banners` (
`id` int NOT NULL,
`img` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of banners
-- ----------------------------
-- ----------------------------
-- Table structure for cake_type
-- ----------------------------
DROP TABLE IF EXISTS `cake_type`;
CREATE TABLE `cake_type` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1753 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of cake_type
-- ----------------------------
INSERT INTO `cake_type` VALUES (1, 'Chocolate', 'For Choco Addicts');
INSERT INTO `cake_type` VALUES (2, 'Fruits', 'A taste of tropics');
INSERT INTO `cake_type` VALUES (3, 'Exotic', 'Oreo, Rochers & more');
INSERT INTO `cake_type` VALUES (4, 'Blackforest', 'The all time Favourite');
INSERT INTO `cake_type` VALUES (5, 'Butterscotch', 'For Candy Fans');
INSERT INTO `cake_type` VALUES (6, 'Vanilla', 'The Evergreen');
INSERT INTO `cake_type` VALUES (7, 'Coffee', 'For Expresso Lover');
INSERT INTO `cake_type` VALUES (8, 'Strawberry', 'An ideal Complement');
-- ----------------------------
-- Table structure for cakes
-- ----------------------------
DROP TABLE IF EXISTS `cakes`;
CREATE TABLE `cakes` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`price` decimal(10, 0) NOT NULL DEFAULT 0,
`size` double NULL DEFAULT NULL,
`description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
`id_cake_type` int NOT NULL,
`image` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `fk_id_type_cake_cakes`(`id_cake_type`) USING BTREE,
CONSTRAINT `fk_id_type_cake_cakes` FOREIGN KEY (`id_cake_type`) REFERENCES `cake_type` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 1475 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of cakes
-- ----------------------------
INSERT INTO `cakes` VALUES (1, 'Blue bery mousse', 300000, 19, 'Blueberry, Kem cheese, Kem tươi. ', 3, '1.1.jpg');
INSERT INTO `cakes` VALUES (2, 'Caramel mousse', 250000, 21, 'Caramel, Socola', 3, '1.2.jpg');
INSERT INTO `cakes` VALUES (3, 'Cherry cheese mousse', 150000, 25, 'Cherry, Kem cheese ,Kem tươi.', 3, '1.3.jpg');
INSERT INTO `cakes` VALUES (4, 'Red chocolate mousse', 400000, 21, 'Kem tươi, Socola,Trà xanh,', 3, '1.4.jpg');
INSERT INTO `cakes` VALUES (5, 'Bánh sinh nhật doremon', 250000, 21, 'Phần kem nhiều màu sắc trên bánh chỉ để trang trí', 1, '2.1.jpg');
INSERT INTO `cakes` VALUES (6, 'Dark chocolate cake', 300000, 21, 'Gato, kem bơ vị rượu rum, socola', 1, '2.2.jpg');
INSERT INTO `cakes` VALUES (7, 'White chocolate and coconut cake', 250000, 19, 'Gato, kem bơ vị rượu rum, socola bào trắng, dừa sấy', 1, '2.3.jpg');
INSERT INTO `cakes` VALUES (8, 'Car dollar cake', 200000, 21, 'Gato, kem, có phụ kiện trên mặt bánh', 1, '2.4.jpg');
INSERT INTO `cakes` VALUES (9, 'Green tea four love', 300000, 23, 'Gato, kem vị trà xanh', 1, '3.1.jpg');
INSERT INTO `cakes` VALUES (10, 'Tiramisu', 220000, 19, 'Gato, kem tươi vị coffee', 1, '3.2.jpg');
INSERT INTO `cakes` VALUES (11, 'Bánh su kem ', 50000, 23, 'Vỏ bánh giòn, xốp, vị kem béo', 5, '3.3.jpg');
INSERT INTO `cakes` VALUES (12, 'Bánh quy mix 4 vị', 100000, 19, 'Vị bánh thơm béo, giòn', 4, '3.4.jpg');
INSERT INTO `cakes` VALUES (13, 'Tiramisu chậu cây', 50000, 19, 'Gato vị socola và trái cây', 4, '4.1.jfif');
INSERT INTO `cakes` VALUES (14, 'Bánh donut tiramisu', 50000, 19, 'Chocolate trắng', 6, '4.2.jfif');
INSERT INTO `cakes` VALUES (15, 'Bánh donut cheese', 20000, 19, 'Phô mai tan chảy, chà bông', 6, '4.3.jfif');
INSERT INTO `cakes` VALUES (16, 'Bánh donut queen', 20000, 19, 'Chocolate trắng, hạnh nhân', 6, '4.4.jfif');
INSERT INTO `cakes` VALUES (17, 'Bánh donut scoopy doo', 20000, 25, 'Chocolate đen, cốm chocolate', 6, '5.1.jpg');
INSERT INTO `cakes` VALUES (18, 'Bánh donut green tea', 20000, 25, 'Socola trà xanh, nhân socolate', 6, '5.2.jpg');
INSERT INTO `cakes` VALUES (19, 'Bánh donut coconut lemon', 20000, 19, 'Chocolate chanh, dừa sấy', 6, '5.3.jpg');
INSERT INTO `cakes` VALUES (20, 'Bánh lúa mạch nẩy mầm', 59000, 23, 'Bột lúa mạch, hạt bí\n', 2, '5.4.jpg');
INSERT INTO `cakes` VALUES (21, 'Baked ham & cheese sw', 45000, 25, 'Bánh Sandwich Kẹp Thịt Ham Và Phô Mai', 2, '6.1.jpg');
INSERT INTO `cakes` VALUES (22, 'Tuna sandwich', 45000, 23, 'Bánh Sandwich Nhân Cá Ngừ', 2, '6.2.jpg');
-- ----------------------------
-- Table structure for cart
-- ----------------------------
DROP TABLE IF EXISTS `cart`;
CREATE TABLE `cart` (
`id_cake` int NOT NULL,
`id_user` int NOT NULL,
`amount` int NOT NULL DEFAULT 1,
PRIMARY KEY (`id_cake`, `id_user`) USING BTREE,
INDEX `fk_id_users_cart`(`id_user`) USING BTREE,
CONSTRAINT `fk_id_cakes_cart` FOREIGN KEY (`id_cake`) REFERENCES `cakes` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `fk_id_users_cart` FOREIGN KEY (`id_user`) REFERENCES `users` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of cart
-- ----------------------------
INSERT INTO `cart` VALUES (1, 2, 4);
INSERT INTO `cart` VALUES (1, 11, 1);
INSERT INTO `cart` VALUES (1, 1749, 1);
INSERT INTO `cart` VALUES (2, 2, 3);
INSERT INTO `cart` VALUES (2, 3, 3);
INSERT INTO `cart` VALUES (3, 4, 1);
INSERT INTO `cart` VALUES (4, 4, 2);
INSERT INTO `cart` VALUES (5, 2, 8);
INSERT INTO `cart` VALUES (5, 5, 1);
INSERT INTO `cart` VALUES (5, 1749, 1);
INSERT INTO `cart` VALUES (6, 2, 4);
INSERT INTO `cart` VALUES (6, 3, 2);
INSERT INTO `cart` VALUES (7, 8, 1);
INSERT INTO `cart` VALUES (7, 1749, 2);
INSERT INTO `cart` VALUES (8, 11, 3);
INSERT INTO `cart` VALUES (8, 1749, 2);
INSERT INTO `cart` VALUES (11, 1749, 1);
-- ----------------------------
-- Table structure for order_details
-- ----------------------------
DROP TABLE IF EXISTS `order_details`;
CREATE TABLE `order_details` (
`id_order` int NOT NULL,
`id_cake` int NOT NULL,
`amount` int NOT NULL DEFAULT 1,
PRIMARY KEY (`id_order`, `id_cake`) USING BTREE,
INDEX `fk_id_cakes_order_details`(`id_cake`) USING BTREE,
CONSTRAINT `fk_id_cakes_order_details` FOREIGN KEY (`id_cake`) REFERENCES `cakes` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `fk_id_order_order_details` FOREIGN KEY (`id_order`) REFERENCES `orders` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of order_details
-- ----------------------------
INSERT INTO `order_details` VALUES (1, 1, 1);
INSERT INTO `order_details` VALUES (1, 3, 2);
INSERT INTO `order_details` VALUES (2, 5, 3);
INSERT INTO `order_details` VALUES (3, 4, 1);
INSERT INTO `order_details` VALUES (4, 8, 3);
INSERT INTO `order_details` VALUES (5, 12, 3);
INSERT INTO `order_details` VALUES (6, 22, 4);
INSERT INTO `order_details` VALUES (7, 5, 5);
INSERT INTO `order_details` VALUES (7, 13, 2);
INSERT INTO `order_details` VALUES (8, 15, 3);
INSERT INTO `order_details` VALUES (9, 16, 2);
INSERT INTO `order_details` VALUES (10, 12, 3);
INSERT INTO `order_details` VALUES (11, 14, 3);
INSERT INTO `order_details` VALUES (12, 19, 3);
INSERT INTO `order_details` VALUES (12, 20, 3);
INSERT INTO `order_details` VALUES (12, 21, 1);
INSERT INTO `order_details` VALUES (13, 17, 2);
INSERT INTO `order_details` VALUES (14, 18, 2);
INSERT INTO `order_details` VALUES (15, 1, 1);
INSERT INTO `order_details` VALUES (15, 4, 3);
-- ----------------------------
-- Table structure for orders
-- ----------------------------
DROP TABLE IF EXISTS `orders`;
CREATE TABLE `orders` (
`id` int NOT NULL AUTO_INCREMENT,
`order_date` date NULL DEFAULT NULL,
`delivery_date` date NULL DEFAULT NULL,
`id_user` int NOT NULL,
`id_status` char(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `fk_id_statues_order`(`id_status`) USING BTREE,
INDEX `fk_id_users_orders`(`id_user`) USING BTREE,
CONSTRAINT `fk_id_statues_order` FOREIGN KEY (`id_status`) REFERENCES `status` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `fk_id_users_orders` FOREIGN KEY (`id_user`) REFERENCES `users` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 1838 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of orders
-- ----------------------------
INSERT INTO `orders` VALUES (1, '2021-05-20', '2021-05-20', 3, 'DG');
INSERT INTO `orders` VALUES (2, '2021-05-21', '2021-05-21', 3, 'DG');
INSERT INTO `orders` VALUES (3, '2021-05-21', '2021-05-22', 4, 'DG');
INSERT INTO `orders` VALUES (4, '2021-05-21', '2021-05-21', 4, 'DG');
INSERT INTO `orders` VALUES (5, '2021-05-24', '2021-05-24', 5, 'DG');
INSERT INTO `orders` VALUES (6, '2021-05-24', '2021-05-25', 2, 'DG');
INSERT INTO `orders` VALUES (7, '2021-05-24', '2021-05-25', 8, 'DG');
INSERT INTO `orders` VALUES (8, '2021-05-25', '2021-05-26', 11, 'DG');
INSERT INTO `orders` VALUES (9, '2021-05-25', '2021-05-26', 11, 'DG');
INSERT INTO `orders` VALUES (10, '2021-05-25', NULL, 8, 'DGH');
INSERT INTO `orders` VALUES (11, '2021-05-26', NULL, 3, 'DGH');
INSERT INTO `orders` VALUES (12, '2021-05-26', NULL, 9, 'DGH');
INSERT INTO `orders` VALUES (13, '2021-05-26', NULL, 5, 'DCB');
INSERT INTO `orders` VALUES (14, '2021-05-27', NULL, 3, 'DCB');
INSERT INTO `orders` VALUES (15, '2021-05-28', NULL, 9, 'CXL');
INSERT INTO `orders` VALUES (16, '2021-05-28', '2021-05-01', 7, 'CXL');
-- ----------------------------
-- Table structure for status
-- ----------------------------
DROP TABLE IF EXISTS `status`;
CREATE TABLE `status` (
`id` char(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of status
-- ----------------------------
INSERT INTO `status` VALUES ('CXL', 'Chưa xử lý');
INSERT INTO `status` VALUES ('DCB', 'Đang chuẩn bị đơn hàng');
INSERT INTO `status` VALUES ('DG', 'Đã giao');
INSERT INTO `status` VALUES ('DGH', 'Đang giao hàng');
-- ----------------------------
-- Table structure for users
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`phone` char(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
`address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
`password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
`role` int NOT NULL DEFAULT 1,
`avatar` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1753 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of users
-- ----------------------------
INSERT INTO `users` VALUES (-9999, 'Quản trị viên', '0000000000', '0000000000', '12345', 'admin', 0, NULL);
INSERT INTO `users` VALUES (2, 'Nguyễn Tùng Lâm', '0338309523', '124 đường Mạc Thiên Tích, phường Xuân Khánh, quận Ninh Kiều, TP.Cần Thơ', '12345', '[email protected]', 1, NULL);
INSERT INTO `users` VALUES (3, 'Nguyễn Hoàng Thông', '0358309329', '12 đường Lý Tự Trọng, phường An Lạc, quận Ninh Kiều, TP.Cần Thơ', '12345', '[email protected]', 1, NULL);
INSERT INTO `users` VALUES (4, 'Hầu Diễm Xuân', '0123763585', '45 đường Trần Hưng Đạo, phường Xuân Khánh, quận Ninh Kiều, TP.Cần Thơ', '12345', '[email protected]', 1, NULL);
INSERT INTO `users` VALUES (5, 'Phạm Chí Trung', '0925385162', '82 đường Trần Văn Hoài, phường Xuân Khánh, quận Ninh Kiều, TP.Cần Thơ', '12345', '[email protected]', 1, NULL);
INSERT INTO `users` VALUES (6, 'Đoàn Duy Thanh', '0873174284', '97 đường Hùng Vương, phường An Cư, quận Ninh Kiều, TP.Cần Thơ', '12345', '[email protected]', 1, NULL);
INSERT INTO `users` VALUES (7, 'Nguyễn Huỳnh Hoàng Phúc', '0836109481', '48 đường Trần Ngọc Quế, phường Xuân Khánh, quận Ninh Kiều, TP.Cần Thơ', '12345', '[email protected]', 1, NULL);
INSERT INTO `users` VALUES (8, 'Trần Văn Thiệt', '0927385387', '178 đường Nguyễn Việt Hồng, phường Xuân Khánh, quận Ninh Kiều, TP.Cần Thơ', '12345', '[email protected]', 1, NULL);
INSERT INTO `users` VALUES (9, 'Nguyễn Thị Thúy Lựu', '0391278359', '132 đường Mậu Thân, phường Xuân Khánh, quận Ninh Kiều, TP.Cần Thơ', '12345', '[email protected]', 1, NULL);
INSERT INTO `users` VALUES (10, 'Trịnh Kim Chi', '0331489511', '228 đường Nguyễn Trãi, phường Cái Khế, quận Ninh Kiều, TP.Cần Thơ', '12345', '[email protected]', 1, NULL);
INSERT INTO `users` VALUES (11, 'Trần Phương Thảo', '0702137273', '312 đường Nguyễn Văn Linh, phường Hưng Lợi, quận Ninh Kiều, TP.Cần Thơ', '12345', '[email protected]', 1, NULL);
INSERT INTO `users` VALUES (1749, 'nguyễn trần bảo khánh', '0123456789', 'cần thơ', '$2y$10$oApjZEZ0Bt5/NxuInuEim.CSYaAJ72RaVOCbGIeDVxKvvoYdLZEam', '[email protected]', 1, 'user.png');
INSERT INTO `users` VALUES (1751, 'khanh1010vn', NULL, NULL, '$2y$10$H.U2G9v4IHvzJJoWjS50aeHGGsI6l1l6hBMB3yOkUA.a5G2kM6H6q', '[email protected]', 1, NULL);
INSERT INTO `users` VALUES (1752, 'khanh1010vn', NULL, NULL, '$2y$10$FSogZCdiGG4TRBjcB5alMe1uSTKJ5tBrtWrYjSKxVS49qGbF8jGlC', '[email protected]', 1, NULL);
-- ----------------------------
-- View structure for v_userlist
-- ----------------------------
DROP VIEW IF EXISTS `v_userlist`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_userlist` AS SELECT U.id as userID, U.address AS address, U.email as email, U.phone as phone, U.NAME AS username, U.avatar as avatar
FROM USERS U ;
-- ----------------------------
-- Procedure structure for sp_itemsInCart
-- ----------------------------
DROP PROCEDURE IF EXISTS `sp_itemsInCart`;
delimiter ;;
CREATE PROCEDURE `sp_itemsInCart`(userID int)
begin
select C.name as cakeName, C.price, C.size, C.description, C.id_cake_type as cakeTypeID, ct.name as cakeType, image
from cart join cakes c on c.id = cart.id_cake
join cake_type ct on ct.id = c.id_cake_type
where id_user = userID;
end
;;
delimiter ;
-- ----------------------------
-- Procedure structure for sp_selectUserByID
-- ----------------------------
DROP PROCEDURE IF EXISTS `sp_selectUserByID`;
delimiter ;;
CREATE PROCEDURE `sp_selectUserByID`(userID int)
begin
SELECT U.id as userID, U.address AS address, U.email as email, U.phone as phone, U.NAME AS username, U.avatar as avatar
from users U
where U.id = userID;
end
;;
delimiter ;
-- ----------------------------
-- Procedure structure for sp_updateState
-- ----------------------------
DROP PROCEDURE IF EXISTS `sp_updateState`;
delimiter ;;
CREATE PROCEDURE `sp_updateState`(orderID int, stateID char(10))
begin
UPDATE orders SET id_status = stateID
where id = orderID;
end
;;
delimiter ;
-- ----------------------------
-- Triggers structure for table orders
-- ----------------------------
DROP TRIGGER IF EXISTS `trg_checkDate`;
delimiter ;;
CREATE TRIGGER `trg_checkDate` BEFORE INSERT ON `orders` FOR EACH ROW begin
if (new.delivery_date < new.order_date)
THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Ngay dat hang khong the lon hon ngay giao hang';
END IF;
end
;;
delimiter ;
-- ----------------------------
-- Triggers structure for table orders
-- ----------------------------
DROP TRIGGER IF EXISTS `trg_checkDateInsert`;
delimiter ;;
CREATE TRIGGER `trg_checkDateInsert` BEFORE INSERT ON `orders` FOR EACH ROW begin
if (new.delivery_date < new.order_date)
THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Ngay dat hang khong the lon hon ngay giao hang';
END IF;
end
;;
delimiter ;
-- ----------------------------
-- Triggers structure for table orders
-- ----------------------------
DROP TRIGGER IF EXISTS `trg_checkDateUpdate`;
delimiter ;;
CREATE TRIGGER `trg_checkDateUpdate` BEFORE UPDATE ON `orders` FOR EACH ROW begin
if (new.delivery_date < new.order_date)
THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Ngay dat hang khong the lon hon ngay giao hang';
END IF;
end
;;
delimiter ;
SET FOREIGN_KEY_CHECKS = 1;