-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBangazonDatabaseFinal.sql
400 lines (383 loc) · 10.6 KB
/
BangazonDatabaseFinal.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
IF (OBJECT_ID('dbo.FK_ComputerEmployee', 'F') IS NOT NULL)
BEGIN
ALTER TABLE dbo.EmployeeComputer DROP CONSTRAINT FK_ComputerEmployee
END
IF (OBJECT_ID('dbo.FK_EmployeeComp', 'F') IS NOT NULL)
BEGIN
ALTER TABLE dbo.EmployeeComputer DROP CONSTRAINT FK_EmployeeComp
END
IF (OBJECT_ID('dbo.FK_TrainingProgram', 'F') IS NOT NULL)
BEGIN
ALTER TABLE dbo.EmployeeTraining DROP CONSTRAINT FK_TrainingProgram
END
IF (OBJECT_ID('dbo.FK_EmployeeTraining', 'F') IS NOT NULL)
BEGIN
ALTER TABLE dbo.EmployeeTraining DROP CONSTRAINT FK_EmployeeTraining
END
IF (OBJECT_ID('dbo.FK_DepartmentEmployee', 'F') IS NOT NULL)
BEGIN
ALTER TABLE dbo.Employee DROP CONSTRAINT FK_DepartmentEmployee
END
IF (OBJECT_ID('dbo.FK_CustomerProduct', 'F') IS NOT NULL)
BEGIN
ALTER TABLE dbo.Product DROP CONSTRAINT FK_CustomerProduct
END
IF (OBJECT_ID('dbo.FK_ProductTypeProduct', 'F') IS NOT NULL)
BEGIN
ALTER TABLE dbo.Product DROP CONSTRAINT FK_ProductTypeProduct
END
IF (OBJECT_ID('dbo.FK_OrderProductOrder', 'F') IS NOT NULL)
BEGIN
ALTER TABLE dbo.ProductOrder DROP CONSTRAINT FK_OrderProductOrder
END
IF (OBJECT_ID('dbo.FK_ProductProductOrder', 'F') IS NOT NULL)
BEGIN
ALTER TABLE dbo.ProductOrder DROP CONSTRAINT FK_ProductProductOrder
END
IF (OBJECT_ID('dbo.FK_CustomerPaymentOrder', 'F') IS NOT NULL)
BEGIN
ALTER TABLE dbo.[Order] DROP CONSTRAINT FK_CustomerPaymentOrder
END
IF (OBJECT_ID('dbo.FK_CustomerOrder', 'F') IS NOT NULL)
BEGIN
ALTER TABLE dbo.[Order] DROP CONSTRAINT FK_CustomerOrder
END
IF (OBJECT_ID('dbo.FK_PaymentTypeCustomer', 'F') IS NOT NULL)
BEGIN
ALTER TABLE dbo.CustomerPayment DROP CONSTRAINT FK_PaymentTypeCustomer
END
IF (OBJECT_ID('dbo.FK_CustomerPayment', 'F') IS NOT NULL)
BEGIN
ALTER TABLE dbo.CustomerPayment DROP CONSTRAINT FK_CustomerPayment
END
DROP TABLE IF EXISTS Department;
DROP TABLE IF EXISTS Employee;
DROP TABLE IF EXISTS EmployeeComputer;
DROP TABLE IF EXISTS EmployeeTraining;
DROP TABLE IF EXISTS [Order];
DROP TABLE IF EXISTS PaymentType;
DROP TABLE IF EXISTS Product;
DROP TABLE IF EXISTS ProductOrder;
DROP TABLE IF EXISTS ProductType;
DROP TABLE IF EXISTS TrainingProgram;
DROP TABLE IF EXISTS Computer;
DROP TABLE IF EXISTS Customer;
DROP TABLE IF EXISTS CustomerPayment;
CREATE TABLE Computer (
ComputerId INTEGER NOT NULL PRIMARY KEY IDENTITY,
DatePurchased DATE NOT NULL,
DateDecommissioned DATE,
Working BIT NOT NULL,
ModelName varchar(80) NOT NULL,
Manufacturer varchar(80) NOT NULL
);
CREATE TABLE TrainingProgram (
TrainingProgramId INTEGER NOT NULL PRIMARY KEY IDENTITY,
ProgramName varchar(80) NOT NULL,
StartDate DATE NOT NULL,
EndDate DATE NOT NULL,
MaximumAttendees INTEGER NOT NULL
);
CREATE TABLE Department (
DepartmentId INTEGER NOT NULL PRIMARY KEY IDENTITY,
DepartmentName varchar(80) NOT NULL,
ExpenseBudget INTEGER NOT NULL
);
CREATE TABLE Employee (
EmployeeId INTEGER NOT NULL PRIMARY KEY IDENTITY,
FirstName varchar(30) NOT NULL,
LastName varchar(30) NOT NULL,
Email varchar(50) NOT NULL,
Supervisor BIT NOT NULL,
DepartmentId INTEGER NOT NULL,
CONSTRAINT FK_DepartmentEmployee FOREIGN KEY(DepartmentId)REFERENCES Department(DepartmentId)
);
CREATE TABLE EmployeeTraining (
EmployeeTrainingId INTEGER NOT NULL PRIMARY KEY IDENTITY,
TrainingProgramId INTEGER NOT NULL,
EmployeeId INTEGER NOT NULL,
CONSTRAINT FK_TrainingProgram FOREIGN KEY(TrainingProgramId)REFERENCES TrainingProgram(TrainingProgramId),
CONSTRAINT FK_EmployeeTraining FOREIGN KEY(EmployeeId)REFERENCES Employee(EmployeeId)
);
CREATE TABLE EmployeeComputer (
EmployeeComputerId INTEGER NOT NULL PRIMARY KEY IDENTITY,
DateAssigned DATE NOT NULL,
DateReturned DATE NOT NULL,
ComputerId INTEGER NOT NULL,
EmployeeId INTEGER NOT NULL,
CONSTRAINT FK_ComputerEmployee FOREIGN KEY(ComputerId)REFERENCES Computer(ComputerId),
CONSTRAINT FK_EmployeeComp FOREIGN KEY(EmployeeId)REFERENCES Employee(EmployeeId)
);
CREATE TABLE Customer (
CustomerId INTEGER NOT NULL PRIMARY KEY IDENTITY,
FirstName varchar(30) NOT NULL,
LastName varchar(30) NOT NULL,
Email varchar(50) NOT NULL,
Address varchar(80) NOT NULL,
City varchar(30) NOT NULL,
State varchar(2) NOT NULL,
AcctCreationDate DATE NOT NULL,
LastLogin DATE NOT NULL
);
CREATE TABLE ProductType (
ProductTypeId INTEGER NOT NULL PRIMARY KEY IDENTITY,
ProductTypeName varchar(30) NOT NULL
);
CREATE TABLE PaymentType (
PaymentTypeId INTEGER NOT NULL PRIMARY KEY IDENTITY,
PaymentTypeName varchar(15) NOT NULL
);
CREATE TABLE CustomerPayment (
CustomerPaymentId INTEGER NOT NULL PRIMARY KEY IDENTITY,
CardNumber BIGINT NOT NULL,
CcvCode varchar(3) NOT NULL,
ExpirationDate varchar(5) NOT NULL,
PaymentTypeId INTEGER NOT NULL,
CustomerId INTEGER NOT NULL,
CONSTRAINT FK_CustomerPayment FOREIGN KEY(CustomerId)REFERENCES Customer(CustomerId),
CONSTRAINT FK_PaymentTypeCustomer FOREIGN KEY(PaymentTypeId)REFERENCES PaymentType(PaymentTypeId)
);
CREATE TABLE [Order] (
OrderId INTEGER NOT NULL PRIMARY KEY IDENTITY,
CustomerId INTEGER NOT NULL,
CustomerPaymentId INTEGER,
CONSTRAINT FK_CustomerOrder FOREIGN KEY(CustomerId)REFERENCES Customer(CustomerId),
CONSTRAINT FK_CustomerPaymentOrder FOREIGN KEY(CustomerPaymentId)REFERENCES CustomerPayment(CustomerPaymentId)
);
CREATE TABLE Product (
ProductId INTEGER NOT NULL PRIMARY KEY IDENTITY,
Price DECIMAL(4, 2) NOT NULL,
Title varchar(55) NOT NULL,
Description varchar(400) NOT NULL,
CustomerId INTEGER NOT NULL,
Quantity INTEGER NOT NULL,
ProductTypeId INTEGER NOT NULL,
CONSTRAINT FK_CustomerProduct FOREIGN KEY(CustomerId)REFERENCES Customer(CustomerId),
CONSTRAINT FK_ProductTypeProduct FOREIGN KEY(ProductTypeId)REFERENCES ProductType(ProductTypeId)
);
CREATE TABLE ProductOrder (
ProductOrderId INTEGER NOT NULL PRIMARY KEY IDENTITY,
OrderId INTEGER NOT NULL,
ProductId INTEGER NOT NULL,
CONSTRAINT FK_OrderProductOrder FOREIGN KEY(OrderId)REFERENCES [Order](OrderId),
CONSTRAINT FK_ProductProductOrder FOREIGN KEY(ProductId)REFERENCES Product(ProductId)
);
INSERT INTO Computer(DatePurchased, DateDecommissioned, Working, ModelName, Manufacturer)
VALUES
(
'2017/10/11',
null,
1,
'XPS',
'Dell');
INSERT INTO Computer(DatePurchased, DateDecommissioned, Working, ModelName, Manufacturer)
VALUES(
'2016/04/01',
'2017/04/15',
0,
'ThinkPad',
'Lenovo');
INSERT INTO TrainingProgram(ProgramName,StartDate,EndDate,MaximumAttendees)
VALUES(
'Learn To Type',
'2018/09/20',
'2018/09/27',
23);
INSERT INTO TrainingProgram(ProgramName,StartDate,EndDate, MaximumAttendees)
VALUES(
'Begining React',
'2017/02/14',
'2017/03/01',
14);
INSERT INTO Department(DepartmentName,ExpenseBudget)
VALUES(
'CodeRockstars',
140234);
INSERT INTO Department(DepartmentName,ExpenseBudget)
VALUES(
'IT',
23400);
INSERT INTO Employee(FirstName,LastName,Email,Supervisor,DepartmentId)
VALUES(
'William',
'Kimball',
1,
1);
INSERT INTO Employee(FirstName,LastName,Email,Supervisor,DepartmentId)
VALUES(
'Robert',
'Leedy',
0,
2);
INSERT INTO EmployeeTraining(TrainingProgramId,EmployeeId)
VALUES(
1,
2);
INSERT INTO EmployeeTraining(TrainingProgramId,EmployeeId)
VALUES(
2,
1);
INSERT INTO EmployeeComputer(DateAssigned,DateReturned,EmployeeId,ComputerId)
VALUES(
'2017/02/14',
'2017/03/01',
2,
1);
INSERT INTO EmployeeComputer(DateAssigned,DateReturned,EmployeeId,ComputerId)
VALUES(
'2017/10/07',
'2017/03/01',
1,
2);
INSERT INTO Customer(FirstName,LastName,Email, Address,City,State,AcctCreationDate,LastLogin)
VALUES(
'Sathvik',
'Reddy',
'123 Main St.',
'Nashville',
'TN',
'2014/03/01',
'2018/03/01');
INSERT INTO Customer(FirstName,LastName,Email, Address,City,State,AcctCreationDate,LastLogin)
VALUES(
'Natasha',
'Cox',
'123 Side St.',
'Nashville',
'TN',
'2012/01/14',
'2018/07/23');
INSERT INTO ProductType(ProductTypeName)
VALUES(
'KnitCap');
INSERT INTO ProductType(ProductTypeName)
VALUES(
'Craft Thing');
INSERT INTO PaymentType ( PaymentTypeName)
VALUES(
'Visa');
INSERT INTO PaymentType(PaymentTypeName)
VALUES(
'MasterCard');
INSERT INTO CustomerPayment (CardNumber,CcvCode,ExpirationDate,PaymentTypeId,CustomerId)
VALUES(
6798620123,
'345',
'03/19',
2,
2);
INSERT INTO CustomerPayment(CardNumber,CcvCode,ExpirationDate,PaymentTypeId,CustomerId)
VALUES(
12343211432,
'213',
'06/23',
1,
1);
INSERT INTO [Order](CustomerPaymentId,CustomerId)
VALUES(
2,
2);
INSERT INTO [Order](CustomerId)
VALUES(
1);
INSERT INTO Product(Price,Title,Description,Quantity,CustomerId,ProductTypeId)
VALUES(
23.40,
'Cap',
'Warm Winter Cap',
1,
2,
1);
INSERT INTO Product (Price,Title,Description,Quantity,CustomerId,ProductTypeId)
VALUES(
13.23,
'Painting',
'Painting of the ocean',
2,
1,
2);
INSERT INTO ProductOrder(OrderId, ProductId)
VALUES(
1,
2);
INSERT INTO ProductOrder(OrderId, ProductId)
VALUES(
1,
2);
INSERT INTO Computer(DatePurchased, DateDecommissioned, Working, ModelName, Manufacturer)
VALUES(
'2018/12/11',
null,
3,
'Pro',
'Mac');
INSERT INTO TrainingProgram(ProgramName,StartDate,EndDate, MaximumAttendees)
VALUES(
'Mastering SQL',
'2018/07/12',
'2018/07/13',
5);
INSERT INTO Department(DepartmentName,ExpenseBudget)
VALUES(
'Sales',
24000);
INSERT INTO Employee(FirstName,LastName,Email,Supervisor,DepartmentId)
VALUES(
'Seth',
'Dana',
0,
3);
INSERT INTO EmployeeTraining(TrainingProgramId,EmployeeId)
VALUES(
3,
3);
INSERT INTO EmployeeComputer(DateAssigned,DateReturned,EmployeeId,ComputerId)
VALUES(
'2017/02/14',
'2018/03/01',
3,
3);
INSERT INTO Customer(FirstName,LastName,Email, Address,City,State,AcctCreationDate,LastLogin)
VALUES(
'Walter',
'White',
'123 5th St.',
'Nashville',
'TN',
'2016/03/01',
'2018/03/01');
INSERT INTO ProductType(ProductTypeName)
VALUES(
'Poem');
INSERT INTO PaymentType (PaymentTypeName)
VALUES(
'Discover');
INSERT INTO CustomerPayment(CardNumber,CcvCode,ExpirationDate,PaymentTypeId,CustomerId)
VALUES(
12343512432,
'133',
'06/33',
3,
3)
INSERT INTO [Order](CustomerPaymentId,CustomerId)
VALUES(
3,
3);
INSERT INTO Product (Price,Title,Description,Quantity,CustomerId,ProductTypeId)
VALUES(
21,
'Love Poem',
'Heart achingly beautiful poem',
3,
3,
3);
INSERT INTO ProductOrder (OrderId, ProductId)
VALUES(
3,
3);