-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_company_db.sql
298 lines (239 loc) · 7.35 KB
/
example_company_db.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
--
-- File generated with SQLiteStudio v3.4.4 on Wed Jun 7 13:53:20 2023
--
-- Text encoding used: UTF-8
--
PRAGMA foreign_keys = off;
BEGIN TRANSACTION;
-- Table: association
DROP TABLE IF EXISTS association;
CREATE TABLE IF NOT EXISTS association (
association_id INTEGER PRIMARY KEY AUTOINCREMENT,
type TEXT
);
INSERT INTO association (
association_id,
type
)
VALUES (
1,
'Customer'
);
INSERT INTO association (
association_id,
type
)
VALUES (
2,
'Manager'
);
INSERT INTO association (
association_id,
type
)
VALUES (
3,
'Employee'
);
INSERT INTO association (
association_id,
type
)
VALUES (
4,
'Owner'
);
-- Table: category
DROP TABLE IF EXISTS category;
CREATE TABLE IF NOT EXISTS category (
category_id INTEGER PRIMARY KEY AUTOINCREMENT
UNIQUE
NOT NULL,
category TEXT
);
INSERT INTO category (
category_id,
category
)
VALUES (
1,
'computing'
);
INSERT INTO category (
category_id,
category
)
VALUES (
2,
'perimeter'
);
INSERT INTO category (
category_id,
category
)
VALUES (
3,
'printer'
);
INSERT INTO category (
category_id,
category
)
VALUES (
4,
'physical'
);
INSERT INTO category (
category_id,
category
)
VALUES (
5,
'security'
);
INSERT INTO category (
category_id,
category
)
VALUES (
6,
'networking'
);
-- Table: category_list
DROP TABLE IF EXISTS category_list;
CREATE TABLE IF NOT EXISTS category_list (
category_list_id INTEGER PRIMARY KEY AUTOINCREMENT,
main REFERENCES category (category_id),
second REFERENCES category (category_id),
third REFERENCES category (category_id)
);
-- Table: company
DROP TABLE IF EXISTS company;
CREATE TABLE IF NOT EXISTS company (
name TEXT,
email TEXT,
phone,
company_id INTEGER PRIMARY KEY AUTOINCREMENT,
business_start NUMERIC,
business_end NUMERIC,
co_owned REFERENCES company (company_id),
co_owned_two NUMERIC
);
-- Table: device
DROP TABLE IF EXISTS device;
CREATE TABLE IF NOT EXISTS device (
device_id INTEGER PRIMARY KEY AUTOINCREMENT,
model_id REFERENCES model (model_id),
manufacturer_id REFERENCES manufacturer (manufacturer),
category_list_id REFERENCES category_list (category_list_id),
serial_id REFERENCES serial (serial_id),
name TEXT,
warranty_id REFERENCES warranty (warranty_id),
location_id REFERENCES location (location_id)
);
-- Table: device_type
DROP TABLE IF EXISTS device_type;
CREATE TABLE IF NOT EXISTS device_type (
device_type_id INTEGER PRIMARY KEY AUTOINCREMENT,
category_id,
device_type
);
INSERT INTO device_type (
device_type_id,
category_id,
device_type
)
VALUES (
1,
NULL,
NULL
);
INSERT INTO device_type (
device_type_id,
category_id,
device_type
)
VALUES (
2,
NULL,
'alarm_panel'
);
INSERT INTO device_type (
device_type_id,
category_id,
device_type
)
VALUES (
3,
NULL,
'access_control'
);
-- Table: did
DROP TABLE IF EXISTS did;
CREATE TABLE IF NOT EXISTS did (
did_id INTEGER PRIMARY KEY AUTOINCREMENT,
did_no NUMERIC,
sip_id REFERENCES sip (sip_id)
);
-- Table: location
DROP TABLE IF EXISTS location;
CREATE TABLE IF NOT EXISTS location (
address,
address_two,
city,
state,
latitude,
longitude,
location_id INTEGER PRIMARY KEY AUTOINCREMENT,
company_id REFERENCES company (company_id)
);
-- Table: manufacturer
DROP TABLE IF EXISTS manufacturer;
CREATE TABLE IF NOT EXISTS manufacturer (
manufacturer_id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT
);
-- Table: model
DROP TABLE IF EXISTS model;
CREATE TABLE IF NOT EXISTS model (
model_id INTEGER PRIMARY KEY AUTOINCREMENT
);
-- Table: person
DROP TABLE IF EXISTS person;
CREATE TABLE IF NOT EXISTS person (
person_id INTEGER PRIMARY KEY AUTOINCREMENT,
company_id REFERENCES company (company_id),
location_id REFERENCES location (location_id)
);
-- Table: phone
DROP TABLE IF EXISTS phone;
CREATE TABLE IF NOT EXISTS phone (
phone_id INTEGER PRIMARY KEY AUTOINCREMENT,
number NUMERIC,
sim TEXT,
model_id REFERENCES model (model_id),
manufacturer_id REFERENCES manufacturer (manufacturer_id),
sip_id REFERENCES sip (sip_id)
);
-- Table: serial
DROP TABLE IF EXISTS serial;
CREATE TABLE IF NOT EXISTS serial (
serial_id INTEGER PRIMARY KEY AUTOINCREMENT,
serial_no TEXT
);
-- Table: sip
DROP TABLE IF EXISTS sip;
CREATE TABLE IF NOT EXISTS sip (
sip_id INTEGER PRIMARY KEY AUTOINCREMENT,
sip_no NUMERIC,
"" REFERENCES company (company_id)
);
-- Table: warranty
DROP TABLE IF EXISTS warranty;
CREATE TABLE IF NOT EXISTS warranty (
warranty_id INTEGER PRIMARY KEY AUTOINCREMENT,
start_date NUMERIC,
end_date NUMERIC
);
COMMIT TRANSACTION;
PRAGMA foreign_keys = on;