forked from nss-ivory-trolls/BangazonAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBangazonAPIScript.sql
More file actions
197 lines (162 loc) · 8.22 KB
/
BangazonAPIScript.sql
File metadata and controls
197 lines (162 loc) · 8.22 KB
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
--DELETE FROM OrderProduct;
--DELETE FROM ComputerEmployee;
--DELETE FROM EmployeeTraining;
--DELETE FROM Employee;
--DELETE FROM TrainingProgram;
--DELETE FROM Computer;
--DELETE FROM Department;
--DELETE FROM [Order];
--DELETE FROM PaymentType;
--DELETE FROM Product;
--DELETE FROM ProductType;
--DELETE FROM Customer;
DROP TABLE IF EXISTS OrderProduct;
DROP TABLE IF EXISTS ComputerEmployee;
DROP TABLE IF EXISTS EmployeeTraining;
DROP TABLE IF EXISTS Employee;
DROP TABLE IF EXISTS TrainingProgram;
DROP TABLE IF EXISTS Computer;
DROP TABLE IF EXISTS Department;
DROP TABLE IF EXISTS [Order];
DROP TABLE IF EXISTS PaymentType;
DROP TABLE IF EXISTS Product;
DROP TABLE IF EXISTS ProductType;
DROP TABLE IF EXISTS Customer;
CREATE TABLE Department (
Id INTEGER NOT NULL PRIMARY KEY IDENTITY,
[Name] VARCHAR(55) NOT NULL,
Budget INTEGER NOT NULL
);
CREATE TABLE Employee (
Id INTEGER NOT NULL PRIMARY KEY IDENTITY,
FirstName VARCHAR(55) NOT NULL,
LastName VARCHAR(55) NOT NULL,
DepartmentId INTEGER NOT NULL,
IsSuperVisor BIT NOT NULL DEFAULT(0),
CONSTRAINT FK_EmployeeDepartment FOREIGN KEY(DepartmentId) REFERENCES Department(Id)
);
CREATE TABLE Computer (
Id INTEGER NOT NULL PRIMARY KEY IDENTITY,
PurchaseDate DATETIME NOT NULL,
DecomissionDate DATETIME,
Make VARCHAR(55) NOT NULL,
Manufacturer VARCHAR(55) NOT NULL
);
CREATE TABLE ComputerEmployee (
Id INTEGER NOT NULL PRIMARY KEY IDENTITY,
EmployeeId INTEGER NOT NULL,
ComputerId INTEGER NOT NULL,
AssignDate DATETIME NOT NULL,
UnassignDate DATETIME,
CONSTRAINT FK_ComputerEmployee_Employee FOREIGN KEY(EmployeeId) REFERENCES Employee(Id),
CONSTRAINT FK_ComputerEmployee_Computer FOREIGN KEY(ComputerId) REFERENCES Computer(Id)
);
CREATE TABLE TrainingProgram (
Id INTEGER NOT NULL PRIMARY KEY IDENTITY,
[Name] VARCHAR(255) NOT NULL,
StartDate DATETIME NOT NULL,
EndDate DATETIME NOT NULL,
MaxAttendees INTEGER NOT NULL
);
CREATE TABLE EmployeeTraining (
Id INTEGER NOT NULL PRIMARY KEY IDENTITY,
EmployeeId INTEGER NOT NULL,
TrainingProgramId INTEGER NOT NULL,
CONSTRAINT FK_EmployeeTraining_Employee FOREIGN KEY(EmployeeId) REFERENCES Employee(Id),
CONSTRAINT FK_EmployeeTraining_Training FOREIGN KEY(TrainingProgramId) REFERENCES TrainingProgram(Id)
);
CREATE TABLE ProductType (
Id INTEGER NOT NULL PRIMARY KEY IDENTITY,
[Name] VARCHAR(55) NOT NULL
);
CREATE TABLE Customer (
Id INTEGER NOT NULL PRIMARY KEY IDENTITY,
FirstName VARCHAR(55) NOT NULL,
LastName VARCHAR(55) NOT NULL
);
CREATE TABLE Product (
Id INTEGER NOT NULL PRIMARY KEY IDENTITY,
ProductTypeId INTEGER NOT NULL,
CustomerId INTEGER NOT NULL,
Price INTEGER NOT NULL,
Title VARCHAR(255) NOT NULL,
[Description] VARCHAR(255) NOT NULL,
Quantity INTEGER NOT NULL,
CONSTRAINT FK_Product_ProductType FOREIGN KEY(ProductTypeId) REFERENCES ProductType(Id),
CONSTRAINT FK_Product_Customer FOREIGN KEY(CustomerId) REFERENCES Customer(Id)
);
CREATE TABLE PaymentType (
Id INTEGER NOT NULL PRIMARY KEY IDENTITY,
AcctNumber INTEGER NOT NULL,
[Name] VARCHAR(55) NOT NULL,
CustomerId INTEGER NOT NULL,
CONSTRAINT FK_PaymentType_Customer FOREIGN KEY(CustomerId) REFERENCES Customer(Id)
);
CREATE TABLE [Order] (
Id INTEGER NOT NULL PRIMARY KEY IDENTITY,
CustomerId INTEGER NOT NULL,
PaymentTypeId INTEGER,
CONSTRAINT FK_Order_Customer FOREIGN KEY(CustomerId) REFERENCES Customer(Id),
CONSTRAINT FK_Order_Payment FOREIGN KEY(PaymentTypeId) REFERENCES PaymentType(Id)
);
CREATE TABLE OrderProduct (
Id INTEGER NOT NULL PRIMARY KEY IDENTITY,
OrderId INTEGER NOT NULL,
ProductId INTEGER NOT NULL,
CONSTRAINT FK_OrderProduct_Product FOREIGN KEY(ProductId) REFERENCES Product(Id),
CONSTRAINT FK_OrderProduct_Order FOREIGN KEY(OrderId) REFERENCES [Order](Id)
);
insert into Computer (PurchaseDate, DecomissionDate, Make, Manufacturer) values ('01 Jan 2019', '01 Jan 2024', 'MacBook Pro', 'Apple')
insert into Computer (PurchaseDate, DecomissionDate, Make, Manufacturer) values ('01 Jan 2018', '01 Jan 2023', 'Inspiron', 'Dell')
insert into Computer (PurchaseDate, DecomissionDate, Make, Manufacturer) values ('01 Jan 2017', '01 Jan 2022', 'MacBook Air', 'Apple')
insert into Department ([Name], Budget) values ('Accounting', 400000)
insert into Department ([Name], Budget) values ('IT', 40000)
insert into Department ([Name], Budget) values ('Sales', 450000)
insert into Employee (FirstName, LastName, DepartmentId, IsSuperVisor) values ('Hernando', 'Rivera', 1, 0)
insert into Employee (FirstName, LastName, DepartmentId, IsSuperVisor) values ('Mary', 'Phillips', 2, 0)
insert into Employee (FirstName, LastName, DepartmentId, IsSuperVisor) values ('Lorenzo', 'Lopez', 1, 1)
insert into Customer (FirstName, LastName) values ('Fred', 'Flinstone')
insert into Customer (FirstName, LastName) values ('Barney', 'Rubble')
insert into Customer (FirstName, LastName) values ('George', 'Jetson')
insert into Customer (FirstName, LastName) values ('Harry', 'Reed')
insert into PaymentType (AcctNumber, [Name], CustomerId) values (1000, 'Visa', 1)
insert into PaymentType (AcctNumber, [Name], CustomerId) values (2000, 'MasterCard', 2)
insert into PaymentType (AcctNumber, [Name], CustomerId) values (3000, 'AmEx', 3)
insert into PaymentType (AcctNumber, [Name], CustomerId) values (4000, 'Bank', 4)
insert into PaymentType (AcctNumber, [Name], CustomerId) values (5000, 'Bank', 4)
insert into [Order] (CustomerId, PaymentTypeId) values (1, 1)
insert into [Order] (CustomerId, PaymentTypeId) values (2, 2)
insert into [Order] (CustomerId) values (3)
insert into ProductType ([Name]) values ('Electronics')
insert into ProductType ([Name]) values ('Sports Equipment')
insert into ProductType ([Name]) values ('Furniture')
insert into Product (ProductTypeId, CustomerId, Title, [Description], Quantity, Price) values (1, 1, 'Television', 'Classic 1970s antique TV', 1, 10)
insert into Product (ProductTypeId, CustomerId, Title, [Description], Quantity, Price) values (2, 2, 'Baseball Bat', 'Wooden', 1, 5)
insert into Product (ProductTypeId, CustomerId, Title, [Description], Quantity, Price) values (3, 3, 'Chair', 'Folding', 1, 3)
insert into ComputerEmployee (EmployeeId, ComputerId, AssignDate, UnassignDate) values (1, 1, '01 Jan 2019', NULL)
insert into ComputerEmployee (EmployeeId, ComputerId, AssignDate, UnassignDate) values (2, 2, '01 Jan 2018', NULL)
insert into ComputerEmployee (EmployeeId, ComputerId, AssignDate, UnassignDate) values (3, 3, '01 Jan 2017', NULL)
insert into TrainingProgram ([Name], StartDate, EndDate, MaxAttendees) values ('How to Count Beans', '14 Feb 2019', '15 Feb 2019', 10)
insert into TrainingProgram ([Name], StartDate, EndDate, MaxAttendees) values ('How to Spell "IT"', '14 Feb 2019', '15 Feb 2019', 10)
insert into TrainingProgram ([Name], StartDate, EndDate, MaxAttendees) values ('How to Sell Beans', '14 Feb 2019', '15 Feb 2019', 10)
insert into TrainingProgram ([Name], StartDate, EndDate, MaxAttendees) values ('How to Sell Cars', '14 Feb 2020', '15 Feb 2020', 12)
insert into EmployeeTraining (EmployeeId, TrainingProgramId) values (1, 1)
insert into EmployeeTraining (EmployeeId, TrainingProgramId) values (2, 2)
insert into EmployeeTraining (EmployeeId, TrainingProgramId) values (3, 3)
insert into EmployeeTraining (EmployeeId, TrainingProgramId) values (3, 4)
insert into OrderProduct (OrderId, ProductId) values (1, 1)
insert into OrderProduct (OrderId, ProductId) values (2, 2)
insert into OrderProduct (OrderId, ProductId) values (2, 2)
insert into OrderProduct (OrderId, ProductId) values (3, 3)
--ALTER TABLE Employee DROP CONSTRAINT [FK_EmployeeDepartment];
--ALTER TABLE ComputerEmployee DROP CONSTRAINT [FK_ComputerEmployee_Employee];
--ALTER TABLE ComputerEmployee DROP CONSTRAINT [FK_ComputerEmployee_Computer];
--ALTER TABLE EmployeeTraining DROP CONSTRAINT [FK_EmployeeTraining_Employee];
--ALTER TABLE EmployeeTraining DROP CONSTRAINT [FK_EmployeeTraining_Training];
--ALTER TABLE Product DROP CONSTRAINT [FK_Product_ProductType];
--ALTER TABLE Product DROP CONSTRAINT [FK_Product_Customer];
--ALTER TABLE PaymentType DROP CONSTRAINT [FK_PaymentType_Customer];
--ALTER TABLE [Order] DROP CONSTRAINT [FK_Order_Customer];
--ALTER TABLE [Order] DROP CONSTRAINT [FK_Order_Payment];
--ALTER TABLE OrderProduct DROP CONSTRAINT [FK_OrderProduct_Product];
--ALTER TABLE OrderProduct DROP CONSTRAINT [FK_OrderProduct_Order];