-
Notifications
You must be signed in to change notification settings - Fork 0
/
DDL_scripts_v2
295 lines (239 loc) · 9.97 KB
/
DDL_scripts_v2
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
-- Generated by Oracle SQL Developer Data Modeler 18.4.0.339.1532
-- at: 2020-02-28 11:38:02 GMT
-- site: Oracle Database 12c
-- type: Oracle Database 12c
CREATE TABLE department (
name VARCHAR2(15 CHAR) NOT NULL,
floor VARCHAR2(2 CHAR) NOT NULL,
ward VARCHAR2(3 CHAR) NOT NULL,
dept_id NUMBER NOT NULL,
hospital_hosp_id NUMBER NOT NULL
);
ALTER TABLE department ADD CONSTRAINT dept_pk PRIMARY KEY ( dept_id );
-- Error - Unique Constraint Department.Department__UN doesn't have columns
CREATE TABLE equipment (
id VARCHAR2(15 CHAR) NOT NULL,
barcode VARCHAR2(12 CHAR) NOT NULL,
name VARCHAR2(20 CHAR) NOT NULL,
category VARCHAR2(25 CHAR) NOT NULL,
quantity NUMBER(3) NOT NULL,
latittude NUMBER(10, 7) NOT NULL,
timestamp TIMESTAMP NOT NULL,
loaned DATE,
return_due DATE,
longitude NUMBER(10, 7) NOT NULL,
longitude2 NUMBER(10, 7) NOT NULL,
person_hospital_id1 VARCHAR2(10 CHAR) NOT NULL,
person_patient_id VARCHAR2(10 CHAR) NOT NULL,
person_staff_id VARCHAR2(10 CHAR) NOT NULL
);
ALTER TABLE equipment
ADD CONSTRAINT equipment_pk PRIMARY KEY ( person_hospital_id1,
id,
person_patient_id,
person_staff_id );
CREATE TABLE hospital (
hosp_id NUMBER NOT NULL,
id VARCHAR2(10 CHAR) NOT NULL,
name VARCHAR2(20 CHAR) NOT NULL,
address VARCHAR2(35 CHAR) NOT NULL,
town VARCHAR2(15 CHAR),
county VARCHAR2(30 CHAR) NOT NULL
);
ALTER TABLE hospital ADD CONSTRAINT hosp_pk PRIMARY KEY ( hosp_id );
ALTER TABLE hospital ADD CONSTRAINT hospital_id_un UNIQUE ( id );
CREATE TABLE ids (
patient_id VARCHAR2(10 CHAR) NOT NULL,
staff_id VARCHAR2(10 CHAR) NOT NULL
);
ALTER TABLE ids ADD CONSTRAINT ids_pk PRIMARY KEY ( patient_id,
staff_id );
CREATE TABLE maintenance (
issue# VARCHAR2(2 CHAR) NOT NULL,
details VARCHAR2(60 CHAR) NOT NULL,
hospital_hosp_id NUMBER NOT NULL
);
CREATE UNIQUE INDEX maintenance__idx ON
maintenance (
hospital_hosp_id
ASC );
CREATE TABLE "Pat-Equip" (
patient_pats_id NUMBER NOT NULL,
equipment_id VARCHAR2(15 CHAR) NOT NULL
);
ALTER TABLE "Pat-Equip" ADD CONSTRAINT "Pat-Equip_PK" PRIMARY KEY ( patient_pats_id,
equipment_id );
CREATE TABLE patient (
patient_pats_id NUMBER NOT NULL,
pats_id VARCHAR2(10) NOT NULL
);
ALTER TABLE patient ADD CONSTRAINT pats_pkv1 PRIMARY KEY ( patient_pats_id );
ALTER TABLE patient ADD CONSTRAINT patient_pats_id_un UNIQUE ( pats_id );
CREATE TABLE "Pers-Equip" (
patient_pats_id NUMBER NOT NULL,
equipment_id VARCHAR2(15 CHAR) NOT NULL
);
ALTER TABLE "Pers-Equip" ADD CONSTRAINT "Pers-Equip_PK" PRIMARY KEY ( patient_pats_id,
equipment_id );
CREATE TABLE person (
surname VARCHAR2(15 CHAR) NOT NULL,
first_name VARCHAR2(15 CHAR) NOT NULL,
address VARCHAR2(25 CHAR) NOT NULL,
town VARCHAR2(15 CHAR),
county VARCHAR2(30 CHAR) NOT NULL,
pats_id NUMBER NOT NULL,
hospital_id VARCHAR2(10 CHAR),
hospital_id1 VARCHAR2(10 CHAR),
ids_patient_id VARCHAR2(10 CHAR) NOT NULL,
ids_staff_id VARCHAR2(10 CHAR) NOT NULL
);
CREATE UNIQUE INDEX person__idx ON
person (
ids_patient_id
ASC,
ids_staff_id
ASC );
ALTER TABLE person ADD CONSTRAINT pats_pk PRIMARY KEY ( pats_id );
ALTER TABLE person
ADD CONSTRAINT person_hospital_id2_un UNIQUE ( hospital_id1,
ids_patient_id,
ids_staff_id );
CREATE TABLE staff (
patient_pats_id NUMBER NOT NULL,
staff_id VARCHAR2(10 CHAR) NOT NULL,
staff_id1 NUMBER NOT NULL
);
ALTER TABLE staff ADD CONSTRAINT staff_pk PRIMARY KEY ( patient_pats_id );
ALTER TABLE staff ADD CONSTRAINT staff_staff_id_un UNIQUE ( staff_id );
ALTER TABLE staff ADD CONSTRAINT staff_staff_id1_un UNIQUE ( staff_id1 );
ALTER TABLE department
ADD CONSTRAINT department_hospital_fk FOREIGN KEY ( hospital_hosp_id )
REFERENCES hospital ( hosp_id );
-- Error - Foreign Key Equipment_Department_FK has no columns
-- Error - Foreign Key Equipment_Maintenance_FK has no columns
ALTER TABLE equipment
ADD CONSTRAINT equipment_person_fk FOREIGN KEY ( person_hospital_id1,
person_patient_id,
person_staff_id )
REFERENCES person ( hospital_id1,
ids_patient_id,
ids_staff_id );
ALTER TABLE maintenance
ADD CONSTRAINT maintenance_hospital_fk FOREIGN KEY ( hospital_hosp_id )
REFERENCES hospital ( hosp_id );
ALTER TABLE "Pat-Equip"
ADD CONSTRAINT "Pat-Equip_Equipment_FK" FOREIGN KEY ( equipment_id )
REFERENCES equipment ( person_hospital_id1,
id,
person_patient_id,
person_staff_id );
ALTER TABLE "Pat-Equip"
ADD CONSTRAINT "Pat-Equip_Patient_FK" FOREIGN KEY ( patient_pats_id )
REFERENCES person ( pats_id );
ALTER TABLE person
ADD CONSTRAINT patient_hospital_fk FOREIGN KEY ( hospital_id )
REFERENCES hospital ( id );
ALTER TABLE patient
ADD CONSTRAINT patientv1_patient_fk FOREIGN KEY ( patient_pats_id )
REFERENCES person ( pats_id );
ALTER TABLE "Pers-Equip"
ADD CONSTRAINT "Pers-Equip_Equipment_FK" FOREIGN KEY ( equipment_id )
REFERENCES equipment ( person_hospital_id1,
id,
person_patient_id,
person_staff_id );
ALTER TABLE "Pers-Equip"
ADD CONSTRAINT "Pers-Equip_Patient_FK" FOREIGN KEY ( patient_pats_id )
REFERENCES person ( pats_id );
ALTER TABLE person
ADD CONSTRAINT person_hospital_fk FOREIGN KEY ( hospital_id1 )
REFERENCES hospital ( id );
ALTER TABLE person
ADD CONSTRAINT person_ids_fk FOREIGN KEY ( ids_patient_id,
ids_staff_id )
REFERENCES ids ( patient_id,
staff_id );
ALTER TABLE staff
ADD CONSTRAINT staff_patient_fk FOREIGN KEY ( patient_pats_id )
REFERENCES person ( pats_id );
-- ERROR: No Discriminator Column found in Arc FKArc_1 - constraint trigger for Arc cannot be generated
-- ERROR: No Discriminator Column found in Arc FKArc_1 - constraint trigger for Arc cannot be generated
CREATE SEQUENCE dept_dept_id_seq START WITH 1 NOCACHE ORDER;
CREATE OR REPLACE TRIGGER dept_dept_id_trg BEFORE
INSERT ON department
FOR EACH ROW
WHEN ( new.dept_id IS NULL )
BEGIN
:new.dept_id := dept_dept_id_seq.nextval;
END;
/
CREATE SEQUENCE hosp_hosp_id_seq START WITH 1 NOCACHE ORDER;
CREATE OR REPLACE TRIGGER hosp_hosp_id_trg BEFORE
INSERT ON hospital
FOR EACH ROW
WHEN ( new.hosp_id IS NULL )
BEGIN
:new.hosp_id := hosp_hosp_id_seq.nextval;
END;
/
CREATE SEQUENCE person_pats_id_seq START WITH 1 NOCACHE ORDER;
CREATE OR REPLACE TRIGGER person_pats_id_trg BEFORE
INSERT ON person
FOR EACH ROW
WHEN ( new.pats_id IS NULL )
BEGIN
:new.pats_id := person_pats_id_seq.nextval;
END;
/
CREATE SEQUENCE staff_staff_id1_seq START WITH 1 NOCACHE ORDER;
CREATE OR REPLACE TRIGGER staff_staff_id1_trg BEFORE
INSERT ON staff
FOR EACH ROW
WHEN ( new.staff_id1 IS NULL )
BEGIN
:new.staff_id1 := staff_staff_id1_seq.nextval;
END;
/
-- Oracle SQL Developer Data Modeler Summary Report:
--
-- CREATE TABLE 10
-- CREATE INDEX 2
-- ALTER TABLE 26
-- CREATE VIEW 0
-- ALTER VIEW 0
-- CREATE PACKAGE 0
-- CREATE PACKAGE BODY 0
-- CREATE PROCEDURE 0
-- CREATE FUNCTION 0
-- CREATE TRIGGER 4
-- ALTER TRIGGER 0
-- CREATE COLLECTION TYPE 0
-- CREATE STRUCTURED TYPE 0
-- CREATE STRUCTURED TYPE BODY 0
-- CREATE CLUSTER 0
-- CREATE CONTEXT 0
-- CREATE DATABASE 0
-- CREATE DIMENSION 0
-- CREATE DIRECTORY 0
-- CREATE DISK GROUP 0
-- CREATE ROLE 0
-- CREATE ROLLBACK SEGMENT 0
-- CREATE SEQUENCE 4
-- CREATE MATERIALIZED VIEW 0
-- CREATE MATERIALIZED VIEW LOG 0
-- CREATE SYNONYM 0
-- CREATE TABLESPACE 0
-- CREATE USER 0
--
-- DROP TABLESPACE 0
-- DROP DATABASE 0
--
-- REDACTION POLICY 0
-- TSDP POLICY 0
--
-- ORDS DROP SCHEMA 0
-- ORDS ENABLE SCHEMA 0
-- ORDS ENABLE OBJECT 0
--
-- ERRORS 5
-- WARNINGS 0