-
Notifications
You must be signed in to change notification settings - Fork 16
/
spare(simplified table).sql
317 lines (172 loc) · 5.39 KB
/
spare(simplified table).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
/*DATABASE AUTO SPARE PART MANAGEMENT
***************************************/
/*Table structure for table category*/
CREATE TABLE category (
CATEGORY_ID int(11),
CNAME varchar(50)
);
/*Table structure for table customer*/
CREATE TABLE customer (
CUST_ID int(11),
FIRST_NAME varchar(50),
LAST_NAME varchar(50),
PHONE_NUMBER varchar(11)
);
/*Table structure for table employee*/
CREATE TABLE employee (
EMPLOYEE_ID int(11),
FIRST_NAME varchar(50),
LAST_NAME varchar(50),
GENDER varchar(50),
EMAIL varchar(100),
PHONE_NUMBER varchar(11),
JOB_ID int(11),
LOCATION_ID int(11)
);
/*Table structure for table job*/
CREATE TABLE job (
JOB_ID int(11),
JOB_TITLE varchar(50)
);
/*Inserting data for table job */
INSERT INTO job ( JOB_ID , JOB_TITLE ) VALUES
(1, 'Manager'),
(2, 'Cashier');
/*Table structure for table location*/
CREATE TABLE location (
LOCATION_ID int(11),
DISTRICT varchar(100),
CITY varchar(100)
);
/*Table structure for table manager*/
CREATE TABLE manager (
FIRST_NAME varchar(50),
LAST_NAME varchar(50),
LOCATION_ID int(11),
EMAIL varchar(50),
PHONE_NUMBER varchar(11)
);
/*Table structure for table product*/
CREATE TABLE product (
PRODUCT_ID int(11),
PRODUCT_CODE varchar(20),
NAME varchar(50),
DESCRIPTION varchar(250) ,
QTY_STOCK int(50) ,
PRICE int(50) ,
CATEGORY_ID int(11) ,
SUPPLIER_ID int(11)
) ;
/*Table structure for table supplier*/
CREATE TABLE supplier (
SUPPLIER_ID int(11) ,
COMPANY_NAME varchar(50) ,
LOCATION_ID int(11) ,
PHONE_NUMBER varchar(11)
) ;
/*Table structure for table transaction */
CREATE TABLE transaction (
TRANS_ID int(50) ,
CUST_ID int(11) ,
NUMOFITEMS varchar(250) ,
SUBTOTAL varchar(50) ,
CASH varchar(250) ,
DATE varchar(50)
) ;
/*Table structure for table transaction_details*/
CREATE TABLE transaction_details (
ID int(11) ,
PRODUCTS varchar(250) ,
QTY varchar(250) ,
PRICE varchar(250) ,
EMPLOYEE varchar(250) ,
ROLE varchar(250)
) ;
/*Table structure for table type */
CREATE TABLE type (
TYPE_ID int(11) ,
TYPE varchar(50)
) ;
/*Inserting data for table type*/
INSERT INTO type ( TYPE_ID , TYPE ) VALUES
(1, 'Admin'),
(2, 'User');
/*Table structure for table users */
CREATE TABLE users (
ID int(11) ,
EMPLOYEE_ID int(11) ,
USERNAME varchar(50) ,
PASSWORD varchar(50) ,
TYPE_ID int(11)
) ;
/*PRIMARY KEY CONSTRAINTS*/
ALTER TABLE category
ADD PRIMARY KEY ( CATEGORY_ID );
ALTER TABLE customer
ADD PRIMARY KEY ( CUST_ID );
ALTER TABLE employee
ADD PRIMARY KEY ( EMPLOYEE_ID );
ALTER TABLE job
ADD PRIMARY KEY ( JOB_ID );
ALTER TABLE location
ADD PRIMARY KEY ( LOCATION_ID );
ALTER TABLE product
ADD PRIMARY KEY ( PRODUCT_ID );
ALTER TABLE supplier
ADD PRIMARY KEY ( SUPPLIER_ID );
ALTER TABLE transaction
ADD PRIMARY KEY ( TRANS_ID );
ALTER TABLE transaction_details
ADD PRIMARY KEY ( ID );
ALTER TABLE type
ADD PRIMARY KEY ( TYPE_ID );
ALTER TABLE users
ADD PRIMARY KEY ( ID );
/*AUTO_INCREMENT for table category */
ALTER TABLE category
MODIFY CATEGORY_ID int(11) AUTO_INCREMENT;
/*AUTO_INCREMENT for table customer */
ALTER TABLE customer
MODIFY CUST_ID int(11) AUTO_INCREMENT;
/*AUTO_INCREMENT for table employee */
ALTER TABLE employee
MODIFY EMPLOYEE_ID int(11) AUTO_INCREMENT;
/*AUTO_INCREMENT for table location*/
ALTER TABLE location
MODIFY LOCATION_ID int(11) AUTO_INCREMENT;
/*AUTO_INCREMENT for table product */
ALTER TABLE product
MODIFY PRODUCT_ID int(11) AUTO_INCREMENT;
/*AUTO_INCREMENT for table supplier */
ALTER TABLE supplier
MODIFY SUPPLIER_ID int(11) AUTO_INCREMENT;
/*AUTO_INCREMENT for table transaction */
ALTER TABLE transaction
MODIFY TRANS_ID int(50) AUTO_INCREMENT;
/*AUTO_INCREMENT for table transaction_details */
ALTER TABLE transaction_details
MODIFY ID int(11) AUTO_INCREMENT;
/*AUTO_INCREMENT for table users */
ALTER TABLE users
MODIFY ID int(11) AUTO_INCREMENT;
/*Constraints for table employee */
ALTER TABLE employee
ADD CONSTRAINT employee_fk_1 FOREIGN KEY ( LOCATION_ID ) REFERENCES location ( LOCATION_ID ),
ADD CONSTRAINT employee_fk_2 FOREIGN KEY ( JOB_ID ) REFERENCES job ( JOB_ID );
/*Constraints for table manager */
ALTER TABLE manager
ADD CONSTRAINT manager_fk_1 FOREIGN KEY ( LOCATION_ID ) REFERENCES location ( LOCATION_ID );
/*Constraints for table product */
ALTER TABLE product
ADD CONSTRAINT product_fk_1 FOREIGN KEY ( CATEGORY_ID ) REFERENCES category ( CATEGORY_ID ),
ADD CONSTRAINT product_fk_2 FOREIGN KEY ( SUPPLIER_ID ) REFERENCES supplier ( SUPPLIER_ID );
/*Constraints for table supplier */
ALTER TABLE supplier
ADD CONSTRAINT supplier_fk_1 FOREIGN KEY ( LOCATION_ID ) REFERENCES location ( LOCATION_ID );
/*Constraints for table transaction */
ALTER TABLE transaction
ADD CONSTRAINT transaction_fk_3 FOREIGN KEY ( CUST_ID ) REFERENCES customer ( CUST_ID );
/*Constraints for table users */
ALTER TABLE users
ADD CONSTRAINT users_fk_3 FOREIGN KEY ( TYPE_ID ) REFERENCES type ( TYPE_ID ),
ADD CONSTRAINT users_fk_4 FOREIGN KEY ( EMPLOYEE_ID ) REFERENCES employee ( EMPLOYEE_ID );