-
Notifications
You must be signed in to change notification settings - Fork 0
/
Complaint_Schema.sql
281 lines (234 loc) · 9.62 KB
/
Complaint_Schema.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
/*==============================================================*/
/* DBMS name: PostgreSQL 14.x */
/* Created on: 11.12.2023 13:51:54 */
/*==============================================================*/
drop index ASSOCIATION_3_FK;
drop index ASSOCIATION_2_FK;
drop index CASE_PK;
drop table "Case";
drop index CHILDSEAT_PK;
drop table ChildSeat;
drop index ASSOCIATION_1_FK;
drop index COMPLAINTID_PK;
drop table ComplaintID;
drop index DEALER_PK;
drop table Dealer;
drop index EQUIPMENT_PK;
drop table Equipment;
drop index FAILPLACE_PK;
drop table FailPlace;
drop index TIRE_PK;
drop table Tire;
drop index VEHICLE_PK;
drop table Vehicle;
/*==============================================================*/
/* Table: "Case" */
/*==============================================================*/
create table "Case" (
ODINO integer not null,
DEALER_NAME varchar(40),
DEALER_ZIP integer,
CITY varchar(30),
STATE varchar(2),
MFR_NAME varchar,
MAKETXT varchar,
MODELTXT varchar,
YEARTXT integer,
CRASH boolean,
FAILDATE date,
FIRE boolean,
INJURED integer,
DEATHS integer,
DATEA date,
LDATE date,
OCCURENCES integer,
CDESCR varchar,
MEDICAL_ATTN boolean,
POLICE_RPT_YN boolean,
PURCH_DT date,
constraint PK_CASE primary key (ODINO)
);
/*==============================================================*/
/* Index: CASE_PK */
/*==============================================================*/
create unique index CASE_PK on "Case" (
ODINO
);
/*==============================================================*/
/* Index: ASSOCIATION_2_FK */
/*==============================================================*/
create index ASSOCIATION_2_FK on "Case" (
DEALER_NAME,
DEALER_ZIP
);
/*==============================================================*/
/* Index: ASSOCIATION_3_FK */
/*==============================================================*/
create index ASSOCIATION_3_FK on "Case" (
CITY,
STATE
);
/*==============================================================*/
/* Table: ChildSeat */
/*==============================================================*/
create table ChildSeat (
ODINO integer not null,
CMPLID integer not null,
RESTRAINT_TYPE varchar(4),
MANUF_DT date,
SEAT_TYPE varchar(4),
constraint PK_CHILDSEAT primary key (ODINO, CMPLID)
);
/*==============================================================*/
/* Index: CHILDSEAT_PK */
/*==============================================================*/
create unique index CHILDSEAT_PK on ChildSeat (
ODINO,
CMPLID
);
/*==============================================================*/
/* Table: ComplaintID */
/*==============================================================*/
create table ComplaintID (
ODINO integer not null,
CMPLID integer not null,
COMPDESC varchar(254),
PROD_TYPE char(1),
constraint PK_COMPLAINTID primary key (ODINO, CMPLID)
);
/*==============================================================*/
/* Index: COMPLAINTID_PK */
/*==============================================================*/
create unique index COMPLAINTID_PK on ComplaintID (
ODINO,
CMPLID
);
/*==============================================================*/
/* Index: ASSOCIATION_1_FK */
/*==============================================================*/
create index ASSOCIATION_1_FK on ComplaintID (
ODINO
);
/*==============================================================*/
/* Table: Dealer */
/*==============================================================*/
create table Dealer (
DEALER_NAME varchar(40) not null,
DEALER_TEL varchar(20),
DEALER_CITY varchar(30) not null,
DEALER_STATE varchar(2) not null,
DEALER_ZIP integer not null,
constraint PK_DEALER primary key (DEALER_NAME, DEALER_ZIP)
);
/*==============================================================*/
/* Index: DEALER_PK */
/*==============================================================*/
create unique index DEALER_PK on Dealer (
DEALER_NAME,
DEALER_ZIP
);
/*==============================================================*/
/* Table: Equipment */
/*==============================================================*/
create table Equipment (
ODINO integer not null,
CMPLID integer not null,
ORIG_OWNER_YN boolean,
constraint PK_EQUIPMENT primary key (ODINO, CMPLID)
);
/*==============================================================*/
/* Index: EQUIPMENT_PK */
/*==============================================================*/
create unique index EQUIPMENT_PK on Equipment (
ODINO,
CMPLID
);
/*==============================================================*/
/* Table: FailPlace */
/*==============================================================*/
create table FailPlace (
CITY varchar(30) not null,
STATE varchar(2) not null,
constraint PK_FAILPLACE primary key (CITY, STATE)
);
/*==============================================================*/
/* Index: FAILPLACE_PK */
/*==============================================================*/
create unique index FAILPLACE_PK on FailPlace (
CITY,
STATE
);
/*==============================================================*/
/* Table: Tire */
/*==============================================================*/
create table Tire (
ODINO integer not null,
CMPLID integer not null,
DOT varchar(20),
TIRE_SIZE varchar(30),
LOC_OF_TIRE varchar(4),
TIRE_FAIL_TYPE varchar(4),
REPAIRED_YN boolean,
constraint PK_TIRE primary key (ODINO, CMPLID)
);
/*==============================================================*/
/* Index: TIRE_PK */
/*==============================================================*/
create unique index TIRE_PK on Tire (
ODINO,
CMPLID
);
/*==============================================================*/
/* Table: Vehicle */
/*==============================================================*/
create table Vehicle (
ODINO integer not null,
CMPLID integer not null,
VIN varchar(11),
MILES integer,
ANTI_BRAKES_YN boolean,
CRUISE_CONT_YN boolean,
NUM_CYLS integer,
DRIVE_TRAIN varchar(4),
FUEL_SYS varchar(4),
FUEL_TYPE varchar(4),
TRANS_TYPE varchar(4),
VEH_SPEED integer,
VEHICLES_TOWED_YN boolean,
constraint PK_VEHICLE primary key (ODINO, CMPLID)
);
/*==============================================================*/
/* Index: VEHICLE_PK */
/*==============================================================*/
create unique index VEHICLE_PK on Vehicle (
ODINO,
CMPLID
);
alter table "Case"
add constraint FK_CASE_ASSOCIATI_DEALER foreign key (DEALER_NAME, DEALER_ZIP)
references Dealer (DEALER_NAME, DEALER_ZIP)
on delete restrict on update restrict;
alter table "Case"
add constraint FK_CASE_ASSOCIATI_FAILPLAC foreign key (CITY, STATE)
references FailPlace (CITY, STATE)
on delete restrict on update restrict;
alter table ChildSeat
add constraint FK_CHILDSEA_GENERALIZ_COMPLAIN foreign key (ODINO, CMPLID)
references ComplaintID (ODINO, CMPLID)
on delete restrict on update restrict;
alter table ComplaintID
add constraint FK_COMPLAIN_ASSOCIATI_CASE foreign key (ODINO)
references "Case" (ODINO)
on delete restrict on update restrict;
alter table Equipment
add constraint FK_EQUIPMEN_GENERALIZ_COMPLAIN foreign key (ODINO, CMPLID)
references ComplaintID (ODINO, CMPLID)
on delete restrict on update restrict;
alter table Tire
add constraint FK_TIRE_GENERALIZ_COMPLAIN foreign key (ODINO, CMPLID)
references ComplaintID (ODINO, CMPLID)
on delete restrict on update restrict;
alter table Vehicle
add constraint FK_VEHICLE_GENERALIZ_COMPLAIN foreign key (ODINO, CMPLID)
references ComplaintID (ODINO, CMPLID)
on delete restrict on update restrict;