-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shoemaker.sql
340 lines (274 loc) · 8.59 KB
/
Shoemaker.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
/*
SQLyog Professional v12.5.1 (64 bit)
MySQL - 8.0.21 : Database - shoemaker
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;
/*!40101 SET SQL_MODE=''*/;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`shoemaker` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
USE `shoemaker`;
/*Table structure for table `belt` */
DROP TABLE IF EXISTS `belt`;
CREATE TABLE `belt` (
`bid` int unsigned NOT NULL AUTO_INCREMENT,
`b_name` varchar(20) DEFAULT NULL,
`b_type` varchar(20) DEFAULT NULL,
`size` char(1) DEFAULT NULL,
`color` varchar(10) DEFAULT NULL,
`price` double DEFAULT NULL,
`buckle_type` varchar(20) DEFAULT NULL,
`total_quantity` int unsigned DEFAULT NULL,
`available` int unsigned DEFAULT NULL,
PRIMARY KEY (`bid`)
) ENGINE=InnoDB AUTO_INCREMENT=116 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*Data for the table `belt` */
insert into `belt`(`bid`,`b_name`,`b_type`,`size`,`color`,`price`,`buckle_type`,`total_quantity`,`available`) values
(100,'Armani','Casual','L','Brown',10000,'Steel',2500,100),
(101,'Prada','Luxury','M','Brown',20000,'Silver',500,499),
(112,'Gucci','Casual','L','Brown',20010,'Metal',200,100),
(113,'Gucci','Casual','L','Brown',20010,'Metal',200,100),
(114,'Gucci','Casual','L','Brown',20010,'Metal',200,100),
(115,'Gucci','Casual','L','Brown',20010,'Metal',200,100);
/*Table structure for table `shoes` */
DROP TABLE IF EXISTS `shoes`;
CREATE TABLE `shoes` (
`sid` int NOT NULL AUTO_INCREMENT,
`s_name` varchar(20) DEFAULT NULL,
`s_type` varchar(20) DEFAULT NULL,
`size` int unsigned DEFAULT NULL,
`color` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
`price` double unsigned DEFAULT NULL,
`is_special` char(1) DEFAULT NULL,
`bid` int unsigned DEFAULT NULL,
`available` int unsigned DEFAULT NULL,
`total_quantity` int unsigned DEFAULT NULL,
PRIMARY KEY (`sid`)
) ENGINE=InnoDB AUTO_INCREMENT=106 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*Data for the table `shoes` */
insert into `shoes`(`sid`,`s_name`,`s_type`,`size`,`color`,`price`,`is_special`,`bid`,`available`,`total_quantity`) values
(101,'Gucci','Joggers',20,'Purple',50000,'N',NULL,200,3000),
(102,'Reebok Xpendables','Joggers',40,'Bluish Orange',23000,'N',NULL,3000,3000),
(103,'Reebok Xpendables','Joggers',40,'Bluish Orange',23000,'N',NULL,3000,4000),
(104,'Rimba','Loafers',38,'Red',25000,'N',NULL,20,20),
(105,'Nike','Joggers',24,'White',20000,'Y',102,200,200);
/* Procedure structure for procedure `sp_add_belt` */
/*!50003 DROP PROCEDURE IF EXISTS `sp_add_belt` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_add_belt`(
p_b_name varchar(20),
p_b_type varchar(20),
p_size char(1),
p_color varchar(20),
p_price double unsigned,
p_buckle_type varchar(20),
p_available int unsigned,
p_total_quantity int unsigned
)
BEGIN
insert into belt (
b_name,
b_type,
size,
color,
price,
buckle_type,
available,
total_quantity)
values
(
p_b_name,
p_b_type,
p_size,
p_color,
p_price,
p_buckle_type,
p_available,
p_total_quantity
);
END */$$
DELIMITER ;
/* Procedure structure for procedure `sp_add_shoes` */
/*!50003 DROP PROCEDURE IF EXISTS `sp_add_shoes` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_add_shoes`(
p_s_name varchar(20),
p_s_type varchar(20),
p_size int unsigned,
p_color varchar(20),
p_price double unsigned,
p_bid int unsigned,
p_is_special char(1),
p_available int unsigned,
p_total_quantity int unsigned
)
BEGIN
insert into shoes (s_name,
s_type,
size,
color,
price,
bid,
is_special,
available,
total_quantity)
values
(
p_s_name,
p_s_type,
p_size,
p_color,
p_price,
p_bid,
p_is_special,
p_available,
p_total_quantity
);
END */$$
DELIMITER ;
/* Procedure structure for procedure `sp_delete_belt` */
/*!50003 DROP PROCEDURE IF EXISTS `sp_delete_belt` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_delete_belt`(p_bid int unsigned)
BEGIN
delete from belt where bid = p_bid;
END */$$
DELIMITER ;
/* Procedure structure for procedure `sp_delete_shoes` */
/*!50003 DROP PROCEDURE IF EXISTS `sp_delete_shoes` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_delete_shoes`(p_sid int unsigned)
BEGIN
delete from shoes where sid = p_sid;
END */$$
DELIMITER ;
/* Procedure structure for procedure `sp_find_belt` */
/*!50003 DROP PROCEDURE IF EXISTS `sp_find_belt` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_find_belt`(p_string varchar(20))
BEGIN
SELECT * FROM belt WHERE b_name LIKE CONCAT('%',p_string,'%');
END */$$
DELIMITER ;
/* Procedure structure for procedure `sp_find_shoes` */
/*!50003 DROP PROCEDURE IF EXISTS `sp_find_shoes` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_find_shoes`(p_string varchar(20))
BEGIN
SELECT * FROM shoes WHERE s_name LIKE CONCAT('%',p_string,'%');
END */$$
DELIMITER ;
/* Procedure structure for procedure `sp_purchase_belt` */
/*!50003 DROP PROCEDURE IF EXISTS `sp_purchase_belt` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_purchase_belt`(p_bid INT UNSIGNED, p_quantity INT UNSIGNED)
BEGIN
SELECT @counter := available FROM belt where bid = p_bid;
UPDATE belt
SET available = @counter- p_quantity
WHERE bid = p_bid;
END */$$
DELIMITER ;
/* Procedure structure for procedure `sp_purchase_shoes` */
/*!50003 DROP PROCEDURE IF EXISTS `sp_purchase_shoes` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_purchase_shoes`(p_sid int unsigned, p_quantity int unsigned)
BEGIN
select @counter := available from shoes where sid = p_sid;
UPDATE shoes
SET available = @counter - p_quantity
WHERE sid = p_sid;
END */$$
DELIMITER ;
/* Procedure structure for procedure `sp_show_belt` */
/*!50003 DROP PROCEDURE IF EXISTS `sp_show_belt` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_show_belt`(p_bid varchar(10))
BEGIN
IF(p_bid IS null)
THEN
SELECT * FROM belt;
ELSE
SELECT * from belt where bid = p_bid;
END IF;
END */$$
DELIMITER ;
/* Procedure structure for procedure `sp_show_shoes` */
/*!50003 DROP PROCEDURE IF EXISTS `sp_show_shoes` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_show_shoes`(p_sid varchar(10))
BEGIN
IF(p_sid IS null)
THEN
SELECT * FROM shoes;
ELSE
SELECT * from shoes where sid = p_sid;
END IF;
END */$$
DELIMITER ;
/* Procedure structure for procedure `sp_update_belt` */
/*!50003 DROP PROCEDURE IF EXISTS `sp_update_belt` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_update_belt`(
p_bid INT UNSIGNED,
p_b_name VARCHAR(100),
p_b_type VARCHAR(100),
p_size char(1),
p_color VARCHAR(100),
p_buckle_type VARCHAR(100),
p_price DOUBLE UNSIGNED,
p_available INT UNSIGNED,
p_total_quantity INT UNSIGNED)
BEGIN
UPDATE belt
SET
b_name = p_b_name,
b_type = p_b_type,
size = p_size,
color = p_color,
price = p_price,
buckle_type = p_buckle_type,
available = p_available,
total_quantity = p_total_quantity
WHERE
bid = p_bid;
END */$$
DELIMITER ;
/* Procedure structure for procedure `sp_update_shoes` */
/*!50003 DROP PROCEDURE IF EXISTS `sp_update_shoes` */;
DELIMITER $$
/*!50003 CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_update_shoes`(
p_sid int unsigned,
p_s_name varchar(100),
p_s_type varchar(100),
p_size int unsigned,
p_color varchar(100),
p_price double unsigned,
p_bid int unsigned,
p_is_special char(1),
p_available int unsigned,
p_total_quantity int unsigned
)
BEGIN
update shoes
set
s_name = p_s_name,
s_type = p_s_type,
size = p_size,
color = p_color,
price = p_price,
bid = p_bid,
is_special = p_is_special,
available = p_available,
total_quantity = p_total_quantity
where
sid = p_sid;
END */$$
DELIMITER ;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;