-
Notifications
You must be signed in to change notification settings - Fork 0
/
final_inventory.sql
400 lines (335 loc) · 10.6 KB
/
final_inventory.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
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
-- phpMyAdmin SQL Dump
-- version 5.2.0
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Nov 26, 2022 at 01:05 PM
-- Server version: 10.4.24-MariaDB
-- PHP Version: 8.1.6
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `inve`
--
DELIMITER $$
--
-- Procedures
--
CREATE DEFINER=`root`@`localhost` PROCEDURE `ExampleProc` () BEGIN
DECLARE done INT DEFAULT 0;
DECLARE fullName VARCHAR(20);
DECLARE cur CURSOR FOR SELECT * FROM customer;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur;
label: LOOP
FETCH cur INTO fullName;
INSERT INTO backup VALUES(fullName);
IF done = 1 THEN LEAVE label;
END IF;
END LOOP;
CLOSE cur;
END$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `Example_Proc` () BEGIN
DECLARE done INT DEFAULT 0;
DECLARE fullName VARCHAR(20);
DECLARE cur CURSOR FOR SELECT fullName FROM customer;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur;
label: LOOP
FETCH cur INTO fullName;
INSERT INTO backup VALUES(fullName);
IF done = 1 THEN LEAVE label;
END IF;
END LOOP;
CLOSE cur;
END$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `get_proc` () BEGIN
SELECT * FROM purchase WHERE quantity <10;
SELECT * FROM purchase WHERE unitPrice>1000;
END$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `proc` () BEGIN
DECLARE done INT DEFAULT 0;
DECLARE fullName VARCHAR(20);
DECLARE cur CURSOR FOR SELECT fullName FROM customer;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur;
label: LOOP
FETCH cur INTO fullName;
INSERT INTO backup VALUES(fullname);
IF done = 1 THEN LEAVE label;
END IF;
END LOOP;
CLOSE cur;
END$$
--
-- Functions
--
CREATE DEFINER=`root`@`localhost` FUNCTION `zero_discount` (`ItemNumber` INT(25)) RETURNS INT(20) DETERMINISTIC BEGIN
DECLARE zero_discount VARCHAR(20);
IF ItemNumber < 3 THEN
SET zero_discount = 0;
ELSEIF (ItemNumber <= 5 AND
ItemNumber >= 4) THEN
SET zero_discount = 2;
END IF;
-- return the customer occupation
RETURN (zero_discount);
END$$
DELIMITER ;
-- --------------------------------------------------------
--
-- Table structure for table `backup`
--
CREATE TABLE `backup` (
`fullname` varchar(40) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Dumping data for table `backup`
--
INSERT INTO `backup` (`fullname`) VALUES
(NULL),
(NULL),
(NULL),
(NULL),
(NULL),
(NULL),
(NULL),
('tharun'),
('Steve Jobs'),
('fgafaf'),
('Bill Gates'),
('sanjay'),
('sahoo');
-- --------------------------------------------------------
--
-- Table structure for table `customer`
--
CREATE TABLE `customer` (
`customerID` int(11) NOT NULL,
`fullName` varchar(100) NOT NULL,
`email` varchar(100) DEFAULT NULL,
`mobile` int(11) NOT NULL,
`address` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Dumping data for table `customer`
--
INSERT INTO `customer` (`customerID`, `fullName`, `email`, `mobile`, `address`) VALUES
(4, 'Bill Gates', '[email protected]', 993737, '45, Palo Alto House, Marine Drive'),
(14, 'Steve Jobs', '[email protected]', 333829832, '1st Floor, Apple House'),
(69, 'fgafaf', ' ghar ', 919191, ' ghar '),
(134, ' sanjay ', ' [email protected] ', 901321212, ' sanjay s house ');
-- --------------------------------------------------------
--
-- Table structure for table `item`
--
CREATE TABLE `item` (
`productID` int(11) NOT NULL,
`itemNumber` varchar(255) NOT NULL,
`itemName` varchar(255) NOT NULL,
`discount` float NOT NULL DEFAULT 0,
`stock` int(11) NOT NULL DEFAULT 0,
`unitPrice` float NOT NULL DEFAULT 0,
`customerID` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Dumping data for table `item`
--
INSERT INTO `item` (`productID`, `itemNumber`, `itemName`, `discount`, `stock`, `unitPrice`, `customerID`) VALUES
(34, '1', 'First Bag', 0, 28, 1500, NULL),
(35, '2', 'School Bag', 0, 5, 500, NULL),
(36, '3', 'Office Bag', 0, 5, 1300, NULL),
(37, '4', 'Leather Bag', 2, 6, 3409, NULL),
(38, '5', 'Travel Bag', 2, 17, 1200, NULL),
(39, '6', 'Gym Bag', 0, 0, 3000, NULL),
(40, '7', 'Handbag', 1.5, 10, 1650, NULL),
(41, '8', 'Laptop Bag', 2.1, 9, 2300, NULL),
(43, '10', 'Sports Bag', 1, 92, 1000, NULL),
(45, '11', 'First Aid Bag', 1.5, 11, 1200, NULL),
(49, '14', 'Hiking Bag', 1.5, 6, 1200, NULL);
-- --------------------------------------------------------
--
-- Table structure for table `purchase`
--
CREATE TABLE `purchase` (
`purchaseID` int(11) NOT NULL,
`itemNumber` varchar(255) NOT NULL,
`purchaseDate` date NOT NULL,
`itemName` varchar(255) NOT NULL,
`unitPrice` float NOT NULL DEFAULT 0,
`quantity` int(11) NOT NULL DEFAULT 0,
`vendorName` varchar(255) NOT NULL DEFAULT 'Test Vendor',
`vendorID` int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Dumping data for table `purchase`
--
INSERT INTO `purchase` (`purchaseID`, `itemNumber`, `purchaseDate`, `itemName`, `unitPrice`, `quantity`, `vendorName`, `vendorID`) VALUES
(39, '1', '2018-05-24', 'First Bag', 1600, 10, 'Johnson and Johnsons Co.', 3),
(40, '2', '2018-05-18', 'First Bag', 2341, 2, 'Louise Vitton Bag', 4),
(41, '4', '2018-05-07', 'Leather Bag', 1234, 3, 'Johnson and Johnsons Co.', 3),
(42, '1', '2018-05-24', 'First Bag', 345, 12, 'Louise Vitton Bag', 4),
(43, '5', '2018-05-03', 'Travel Bag', 35, 3, 'Johnson and Johnsons Co.', 3),
(44, '5', '2018-05-16', 'Travel Bag', 3000, 2, 'ABC Company', 1),
(45, '5', '2018-05-21', 'Travel Bag', 3000, 10, 'Sample Vendor 222', 2),
(46, '4', '2018-05-19', 'Leather Bag', 1200, 4, 'Johnson and Johnsons Co.', 3),
(47, '2', '2018-05-10', 'School Bag', 2, 1, 'Sample Vendor 222', 2);
-- --------------------------------------------------------
--
-- Table structure for table `sale`
--
CREATE TABLE `sale` (
`saleID` int(11) NOT NULL,
`itemNumber` varchar(255) NOT NULL,
`customerID` int(11) NOT NULL,
`saleDate` date NOT NULL,
`discount` float NOT NULL DEFAULT 0,
`quantity` int(11) NOT NULL DEFAULT 0,
`unitPrice` float(10,0) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Dumping data for table `sale`
--
INSERT INTO `sale` (`saleID`, `itemNumber`, `customerID`, `saleDate`, `discount`, `quantity`, `unitPrice`) VALUES
(1, '3', 4, '2018-05-24', 5, 2, 1300),
(2, '1', 39, '2018-05-24', 0, 111, 1500),
(3, '4', 18, '2018-05-24', 2, 1, 3409),
(4, '5', 25, '2018-05-24', 2, 1, 1200),
(5, '6', 24, '2018-05-24', 0, 1, 3000),
(6, '7', 14, '2018-05-24', 1.5, 1, 1650),
(7, '1', 14, '0000-00-00', 0, 5, 1500);
--
-- Triggers `sale`
--
DELIMITER $$
CREATE TRIGGER `major_sale` BEFORE INSERT ON `sale` FOR EACH ROW BEGIN
IF NEW.discount<5 THEN SET NEW.discount=0;
END IF;
END
$$
DELIMITER ;
-- --------------------------------------------------------
--
-- Table structure for table `user`
--
CREATE TABLE `user` (
`userID` int(11) NOT NULL,
`fullName` varchar(255) NOT NULL,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`customerID` int(11) DEFAULT NULL,
`vendorID` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Dumping data for table `user`
--
INSERT INTO `user` (`userID`, `fullName`, `username`, `password`, `customerID`, `vendorID`) VALUES
(5, 'bill gates', 'bill gates', '81dc9bdb52d04dc20036dbd8313ed055', 4, NULL),
(6, 'steve jobs', 'steve jobs', '0cc175b9c0f1b6a831c399e269772661', 14, NULL),
(7, 'admin', 'admin', '21232f297a57a5a743894a0e4a801fc3', 69, NULL);
-- --------------------------------------------------------
--
-- Table structure for table `vendor`
--
CREATE TABLE `vendor` (
`vendorID` int(11) NOT NULL,
`fullName` varchar(255) NOT NULL,
`email` varchar(255) DEFAULT NULL,
`mobile` int(11) NOT NULL,
`address` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Dumping data for table `vendor`
--
INSERT INTO `vendor` (`vendorID`, `fullName`, `email`, `mobile`, `address`) VALUES
(2, 'Sample Vendor 222', '[email protected]', 99828282, '123, A Road, B avenue '),
(3, 'Johnson and Johnsons Co.', '32323', 0, '34, Malwatta Road'),
(4, 'Louise Vitton Bag', '[email protected]', 323234938, '45, Palmer Valley'),
(10, 'ABC Company', '2343567', 0, '80, Ground Floor, ABC Shopping Complex');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `customer`
--
ALTER TABLE `customer`
ADD PRIMARY KEY (`customerID`);
--
-- Indexes for table `item`
--
ALTER TABLE `item`
ADD PRIMARY KEY (`productID`);
--
-- Indexes for table `purchase`
--
ALTER TABLE `purchase`
ADD PRIMARY KEY (`purchaseID`),
ADD KEY `vendorID` (`vendorID`);
--
-- Indexes for table `sale`
--
ALTER TABLE `sale`
ADD PRIMARY KEY (`saleID`);
--
-- Indexes for table `user`
--
ALTER TABLE `user`
ADD PRIMARY KEY (`userID`),
ADD KEY `customerID` (`customerID`),
ADD KEY `vendorID` (`vendorID`);
--
-- Indexes for table `vendor`
--
ALTER TABLE `vendor`
ADD PRIMARY KEY (`vendorID`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `customer`
--
ALTER TABLE `customer`
MODIFY `customerID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1346;
--
-- AUTO_INCREMENT for table `item`
--
ALTER TABLE `item`
MODIFY `productID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=50;
--
-- AUTO_INCREMENT for table `purchase`
--
ALTER TABLE `purchase`
MODIFY `purchaseID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=53;
--
-- AUTO_INCREMENT for table `sale`
--
ALTER TABLE `sale`
MODIFY `saleID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=18;
--
-- AUTO_INCREMENT for table `user`
--
ALTER TABLE `user`
MODIFY `userID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;
--
-- AUTO_INCREMENT for table `vendor`
--
ALTER TABLE `vendor`
MODIFY `vendorID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;
--
-- Constraints for dumped tables
--
--
-- Constraints for table `user`
--
ALTER TABLE `user`
ADD CONSTRAINT `user_ibfk_1` FOREIGN KEY (`customerID`) REFERENCES `customer` (`customerID`),
ADD CONSTRAINT `user_ibfk_2` FOREIGN KEY (`vendorID`) REFERENCES `vendor` (`vendorID`);
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;