-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_script.ddl
362 lines (294 loc) · 11.1 KB
/
create_script.ddl
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
-- Generated by Oracle SQL Developer Data Modeler 18.4.0.339.1536
-- at: 2019-04-20 23:44:52 CEST
-- site: Oracle Database 11g
-- type: Oracle Database 11g
--------------------------------------------------------------------------------------------------------------------------------
create or replace procedure DELETE_ALL_TABLES AS
begin
for iRec in
(select distinct OBJECT_TYPE, OBJECT_NAME,
'drop '||OBJECT_TYPE||' "'||OBJECT_NAME||'"'||
case OBJECT_TYPE when 'TABLE' then ' cascade constraints purge' else ' ' end as COMMAND
from USER_OBJECTS where OBJECT_NAME not in ('DELETE_ALL_TABLES', 'SWITCH_FK_OFF', 'SWITCH_FK_ON', 'DELETE_ALL_DATA_FROM_TABLES')
) loop
begin
dbms_output.put_line('Command: '||irec.COMMAND);
execute immediate iRec.COMMAND;
exception
when others then dbms_output.put_line('FAILED!');
end;
end loop;
end;
/
--------------------------------------------------------------------------------------------------------------------------------
create or replace procedure SWITCH_FK_OFF as
begin
for cur in (select CONSTRAINT_NAME, TABLE_NAME from USER_CONSTRAINTS where CONSTRAINT_TYPE = 'R' )
loop
execute immediate 'alter table '||cur.TABLE_NAME||' modify constraint "'||cur.CONSTRAINT_NAME||'" DISABLE';
end loop;
end SWITCH_FK_OFF;
/
--------------------------------------------------------------------------------------------------------------------------------
create or replace procedure SWITCH_FK_ON as
begin
for cur in (select CONSTRAINT_NAME, TABLE_NAME from USER_CONSTRAINTS where CONSTRAINT_TYPE = 'R' )
loop
execute immediate 'alter table '||cur.TABLE_NAME||' modify constraint "'||cur.CONSTRAINT_NAME||'" enable validate';
end loop;
end SWITCH_FK_ON;
/
--------------------------------------------------------------------------------------------------------------------------------
create or replace procedure DELETE_ALL_DATA_FROM_TABLES is
begin
SWITCH_FK_OFF;
for v_rec in (select distinct TABLE_NAME from USER_TABLES)
loop
execute immediate 'truncate table '||v_rec.TABLE_NAME||' drop storage';
end loop;
SWITCH_FK_ON;
for v_rec in (select distinct SEQUENCE_NAME from USER_SEQUENCES)
loop
execute immediate 'alter sequence '||v_rec.SEQUENCE_NAME||' restart start with 1';
end loop;
end DELETE_ALL_DATA_FROM_TABLES;
/
--------------------------------------------------------------------------------------------------------------------------------
exec DELETE_ALL_TABLES;
--------------------------------------------------------------------------------------------------------------------------------
CREATE TABLE battle (
id_battle INTEGER NOT NULL,
location_name VARCHAR2(25 CHAR) NOT NULL
);
ALTER TABLE battle ADD CONSTRAINT battle_pk PRIMARY KEY ( id_battle,
location_name );
CREATE TABLE class (
name VARCHAR2(15 CHAR) NOT NULL,
type_of_armor VARCHAR2(15 CHAR) DEFAULT 'Plate' NOT NULL,
melee_or_range VARCHAR2(15 CHAR) DEFAULT 'Both'
);
ALTER TABLE class
ADD CHECK ( type_of_armor IN (
'Cloth',
'Leather',
'Mail',
'Plate'
) );
ALTER TABLE class
ADD CHECK ( melee_or_range IN (
'Both',
'Melee',
'Range'
) );
ALTER TABLE class ADD CONSTRAINT class_pk PRIMARY KEY ( name );
CREATE TABLE class_weapon (
class_name VARCHAR2(15 CHAR) NOT NULL,
weapon_type VARCHAR2(25 CHAR) NOT NULL
);
ALTER TABLE class_weapon ADD CONSTRAINT class_weapon_pk PRIMARY KEY ( class_name,
weapon_type );
CREATE TABLE continent (
name VARCHAR2(25 CHAR) NOT NULL
);
ALTER TABLE continent ADD CONSTRAINT continent_pk PRIMARY KEY ( name );
CREATE TABLE creature (
name VARCHAR2(25 CHAR) NOT NULL,
class_name VARCHAR2(15 CHAR) NOT NULL,
mount_name VARCHAR2(75 CHAR),
race_name VARCHAR2(15 CHAR) NOT NULL,
location_name VARCHAR2(25 CHAR) NOT NULL,
weapon_type VARCHAR2(25 CHAR) NOT NULL,
gender VARCHAR2(7 CHAR) DEFAULT 'Male' NOT NULL
);
ALTER TABLE creature
ADD CHECK ( gender IN (
'Female',
'Male'
) );
ALTER TABLE creature ADD CONSTRAINT creature_pk PRIMARY KEY ( name );
CREATE TABLE healer (
class_name VARCHAR2(15 CHAR) NOT NULL,
specialization VARCHAR2(25 CHAR) DEFAULT 'Combined',
popularity INTEGER
);
ALTER TABLE healer
ADD CHECK ( specialization IN (
'Combined',
'Many_targets',
'Solo_target'
) );
ALTER TABLE healer ADD CHECK ( popularity BETWEEN 0 AND 100 );
ALTER TABLE healer ADD CONSTRAINT healer_pk PRIMARY KEY ( class_name );
CREATE TABLE location (
name VARCHAR2(25 CHAR) NOT NULL,
type VARCHAR2(15 CHAR) NOT NULL,
continent_name VARCHAR2(25 CHAR) NOT NULL
);
ALTER TABLE location
ADD CHECK ( type IN (
'Desert',
'Forest',
'Mountainous',
'Plain',
'Snowy',
'Underground',
'Water'
) );
ALTER TABLE location ADD CONSTRAINT location_pk PRIMARY KEY ( name );
CREATE TABLE mount (
name VARCHAR2(75 CHAR) NOT NULL,
type VARCHAR2(15 CHAR) DEFAULT 'Ground' NOT NULL,
rarity INTEGER
);
ALTER TABLE mount
ADD CHECK ( type IN (
'Flying',
'Ground',
'Water'
) );
ALTER TABLE mount ADD CHECK ( rarity BETWEEN 0 AND 100 );
ALTER TABLE mount ADD CONSTRAINT mount_pk PRIMARY KEY ( name );
CREATE TABLE mount_location (
mount_name VARCHAR2(75 CHAR) NOT NULL,
location_name VARCHAR2(25 CHAR) NOT NULL
);
ALTER TABLE mount_location ADD CONSTRAINT mount_location_pk PRIMARY KEY ( mount_name,
location_name );
CREATE TABLE race (
name VARCHAR2(15 CHAR) NOT NULL,
fraction VARCHAR2(15 CHAR) NOT NULL
);
ALTER TABLE race
ADD CHECK ( fraction IN (
'Alliance',
'Horde',
'Neutral'
) );
ALTER TABLE race ADD CONSTRAINT race_pk PRIMARY KEY ( name );
CREATE TABLE race_class (
class_name VARCHAR2(15 CHAR) NOT NULL,
race_name VARCHAR2(15 CHAR) NOT NULL
);
ALTER TABLE race_class ADD CONSTRAINT race_class_pk PRIMARY KEY ( class_name,
race_name );
CREATE TABLE tank (
class_name VARCHAR2(15 CHAR) NOT NULL,
popularity INTEGER
);
ALTER TABLE tank ADD CHECK ( popularity BETWEEN 0 AND 100 );
ALTER TABLE tank ADD CONSTRAINT tank_pk PRIMARY KEY ( class_name );
CREATE TABLE weapon (
type VARCHAR2(25 CHAR) NOT NULL,
offhand_weapon VARCHAR2(25 CHAR)
);
ALTER TABLE weapon
ADD CHECK ( type IN (
'Axe',
'Bow',
'Crossbow',
'Dagger',
'Fist_Weapon',
'Hammer',
'Mace',
'Rifle',
'Staff',
'Sword',
'Wand',
'Warglaive'
) );
ALTER TABLE weapon
ADD CHECK ( offhand_weapon IN (
'Dagger',
'Fist_Weapon',
'Grimoire',
'Shield',
'Warglaive'
) );
ALTER TABLE weapon ADD CONSTRAINT weapon_pk PRIMARY KEY ( type );
ALTER TABLE battle
ADD CONSTRAINT battle_location_fk FOREIGN KEY ( location_name )
REFERENCES location ( name );
ALTER TABLE class_weapon
ADD CONSTRAINT class_weapon_class_fk FOREIGN KEY ( class_name )
REFERENCES class ( name );
ALTER TABLE class_weapon
ADD CONSTRAINT class_weapon_weapon_fk FOREIGN KEY ( weapon_type )
REFERENCES weapon ( type );
ALTER TABLE creature
ADD CONSTRAINT creature_class_fk FOREIGN KEY ( class_name )
REFERENCES class ( name );
ALTER TABLE creature
ADD CONSTRAINT creature_location_fk FOREIGN KEY ( location_name )
REFERENCES location ( name );
ALTER TABLE creature
ADD CONSTRAINT creature_mount_fk FOREIGN KEY ( mount_name )
REFERENCES mount ( name );
ALTER TABLE creature
ADD CONSTRAINT creature_race_fk FOREIGN KEY ( race_name )
REFERENCES race ( name );
ALTER TABLE creature
ADD CONSTRAINT creature_weapon_fk FOREIGN KEY ( weapon_type )
REFERENCES weapon ( type );
ALTER TABLE healer
ADD CONSTRAINT healer_class_fk FOREIGN KEY ( class_name )
REFERENCES class ( name );
ALTER TABLE location
ADD CONSTRAINT location_continent_fk FOREIGN KEY ( continent_name )
REFERENCES continent ( name );
ALTER TABLE mount_location
ADD CONSTRAINT mount_location_location_fk FOREIGN KEY ( location_name )
REFERENCES location ( name );
ALTER TABLE mount_location
ADD CONSTRAINT mount_location_mount_fk FOREIGN KEY ( mount_name )
REFERENCES mount ( name );
ALTER TABLE race_class
ADD CONSTRAINT race_class_class_fk FOREIGN KEY ( class_name )
REFERENCES class ( name );
ALTER TABLE race_class
ADD CONSTRAINT race_class_race_fk FOREIGN KEY ( race_name )
REFERENCES race ( name );
ALTER TABLE tank
ADD CONSTRAINT tank_class_fk FOREIGN KEY ( class_name )
REFERENCES class ( name );
-- Oracle SQL Developer Data Modeler Summary Report:
--
-- CREATE TABLE 13
-- CREATE INDEX 0
-- ALTER TABLE 40
-- CREATE VIEW 0
-- ALTER VIEW 0
-- CREATE PACKAGE 0
-- CREATE PACKAGE BODY 0
-- CREATE PROCEDURE 0
-- CREATE FUNCTION 0
-- CREATE TRIGGER 0
-- 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 0
-- 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
--
-- ORDS DROP SCHEMA 0
-- ORDS ENABLE SCHEMA 0
-- ORDS ENABLE OBJECT 0
--
-- ERRORS 0
-- WARNINGS 0