Mercurial > dive4elements > river
comparison flys-backend/doc/schema/oracle.sql @ 3813:6aeee2250418 pre2.6-2011-12-05
merged flys-backend/pre2.6-2011-12-05
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:54 +0200 |
parents | 418a0918863b |
children | fe89d6cf55fb |
comparison
equal
deleted
inserted
replaced
3812:f788d2d901d6 | 3813:6aeee2250418 |
---|---|
1 -- ANNOTATION_TYPES | |
2 CREATE SEQUENCE ANNOTATION_TYPES_ID_SEQ; | |
3 | |
4 CREATE TABLE annotation_types ( | |
5 id NUMBER(38,0) NOT NULL, | |
6 name VARCHAR2(255), | |
7 PRIMARY KEY (id) | |
8 ); | |
9 | |
10 | |
11 -- ANNOTATIONS | |
12 CREATE SEQUENCE ANNOTATIONS_ID_SEQ; | |
13 | |
14 CREATE TABLE annotations ( | |
15 id NUMBER(38,0) NOT NULL, | |
16 attribute_id NUMBER(38,0), | |
17 edge_id NUMBER(38,0), | |
18 position_id NUMBER(38,0), | |
19 range_id NUMBER(38,0), | |
20 type_id NUMBER(38,0), | |
21 PRIMARY KEY (id) | |
22 ); | |
23 | |
24 | |
25 -- ATTRIBUTES | |
26 CREATE SEQUENCE ATTRIBUTES_ID_SEQ; | |
27 | |
28 CREATE TABLE attributes ( | |
29 id NUMBER(38,0) NOT NULL, | |
30 value VARCHAR2(255), | |
31 primary key (id) | |
32 ); | |
33 | |
34 | |
35 -- CROSS_SECTION_LINES | |
36 CREATE SEQUENCE CROSS_SECTION_LINES_ID_SEQ; | |
37 | |
38 CREATE TABLE cross_section_lines ( | |
39 id NUMBER(38,0) NOT NULL, | |
40 km NUMBER(38,2), | |
41 cross_section_id NUMBER(38,0), | |
42 PRIMARY KEY (id) | |
43 ); | |
44 | |
45 | |
46 -- CROSS_SECTION_POINTS | |
47 CREATE SEQUENCE CROSS_SECTION_POINTS_ID_SEQ; | |
48 | |
49 CREATE TABLE cross_section_points ( | |
50 id NUMBER(38,0) NOT NULL, | |
51 col_pos NUMBER(38,0), | |
52 x NUMBER(38,2), | |
53 y NUMBER(38,2), | |
54 cross_section_line_id NUMBER(38,0), | |
55 PRIMARY KEY (id) | |
56 ); | |
57 | |
58 | |
59 -- CROSS_SECTIONS | |
60 create sequence CROSS_SECTIONS_ID_SEQ; | |
61 | |
62 create table cross_sections ( | |
63 id NUMBER(38,0) NOT NULL, | |
64 description VARCHAR2(255), | |
65 river_id NUMBER(38,0), | |
66 time_interval_id NUMBER(38,0), | |
67 PRIMARY KEY (id) | |
68 ); | |
69 | |
70 | |
71 -- DISCHARGE_TABLE_VALUES | |
72 CREATE SEQUENCE DISCHARGE_TABLE_VALUES_ID_SEQ; | |
73 | |
74 CREATE TABLE discharge_table_values ( | |
75 id NUMBER(38,0) NOT NULL, | |
76 q NUMBER(38,2), | |
77 w NUMBER(38,2), | |
78 table_id NUMBER(38,0), | |
79 PRIMARY KEY (id) | |
80 ); | |
81 | |
82 | |
83 -- DISCHARGE_TABLES | |
84 CREATE SEQUENCE DISCHARGE_TABLES_ID_SEQ; | |
85 | |
86 CREATE TABLE discharge_tables ( | |
87 id NUMBER(38,0) NOT NULL, | |
88 description VARCHAR2(255), | |
89 kind NUMBER(38,0), | |
90 gauge_id NUMBER(38,0), | |
91 time_interval_id NUMBER(38,0), | |
92 PRIMARY KEY (id) | |
93 ); | |
94 | |
95 | |
96 -- EDGES | |
97 CREATE SEQUENCE EDGES_ID_SEQ; | |
98 | |
99 CREATE TABLE edges ( | |
100 id NUMBER(38,0) NOT NULL, | |
101 bottom NUMBER(38,2), | |
102 top NUMBER(38,2), | |
103 PRIMARY KEY (id) | |
104 ); | |
105 | |
106 | |
107 -- GAUGES | |
108 CREATE SEQUENCE GAUGES_ID_SEQ; | |
109 | |
110 CREATE TABLE gauges ( | |
111 id NUMBER(38,0) NOT NULL, | |
112 aeo NUMBER(38,2), | |
113 datum NUMBER(38,2), | |
114 name VARCHAR2(255), | |
115 station NUMBER(38,2), | |
116 range_id NUMBER(38,0), | |
117 river_id NUMBER(38,0), | |
118 PRIMARY KEY (id) | |
119 ); | |
120 | |
121 | |
122 -- HYK_ENTRIES | |
123 CREATE SEQUENCE HYK_ENTRIES_ID_SEQ; | |
124 | |
125 CREATE TABLE hyk_entries ( | |
126 id NUMBER(38,0) NOT NULL, | |
127 km NUMBER(38,2), | |
128 measure TIMESTAMP, | |
129 hyk_id NUMBER(38,0), | |
130 PRIMARY KEY (id) | |
131 ); | |
132 | |
133 | |
134 -- HYK_FLOW_ZONE_TYPES | |
135 CREATE SEQUENCE HYK_FLOW_ZONE_TYPES_ID_SEQ; | |
136 | |
137 CREATE TABLE hyk_flow_zone_types ( | |
138 id NUMBER(38,0) NOT NULL, | |
139 description VARCHAR2(255), | |
140 name VARCHAR2(255), | |
141 PRIMARY KEY (id) | |
142 ); | |
143 | |
144 | |
145 -- HYK_FLOW_ZONES | |
146 CREATE SEQUENCE HYK_FLOW_ZONES_ID_SEQ; | |
147 | |
148 CREATE TABLE hyk_flow_zones ( | |
149 id NUMBER(38,0) NOT NULL, | |
150 a NUMBER(38,2), | |
151 b NUMBER(38,2), | |
152 formation_id NUMBER(38,0), | |
153 type_id NUMBER(38,0), | |
154 primary key (id) | |
155 ); | |
156 | |
157 | |
158 -- HYK_FORMATIONS | |
159 CREATE SEQUENCE HYK_FORMATIONS_ID_SEQ; | |
160 | |
161 CREATE TABLE hyk_formations ( | |
162 id NUMBER(38,0) NOT NULL, | |
163 bottom NUMBER(38,2), | |
164 distance_hf NUMBER(38,2), | |
165 distance_vl NUMBER(38,2), | |
166 distance_vr NUMBER(38,2), | |
167 formation_num NUMBER(38,0), | |
168 top NUMBER(38,2), | |
169 hyk_entry_id NUMBER(38,0), | |
170 PRIMARY KEY (id) | |
171 ); | |
172 | |
173 | |
174 -- HYKS | |
175 CREATE SEQUENCE HYKS_ID_SEQ; | |
176 | |
177 CREATE TABLE hyks ( | |
178 id NUMBER(38,0) NOT NULL, | |
179 description VARCHAR2(255), | |
180 river_id NUMBER(38,0), | |
181 primary key (id) | |
182 ); | |
183 | |
184 | |
185 -- MAIN_VALUE_TYPES | |
186 CREATE SEQUENCE MAIN_VALUE_TYPES_ID_SEQ; | |
187 | |
188 CREATE TABLE main_value_types ( | |
189 id NUMBER(38,0) NOT NULL, | |
190 name VARCHAR2(255), | |
191 PRIMARY KEY (id) | |
192 ); | |
193 | |
194 | |
195 -- MAIN_VALUES | |
196 CREATE SEQUENCE MAIN_VALUES_ID_SEQ; | |
197 | |
198 CREATE TABLE main_values ( | |
199 id NUMBER(38,0) NOT NULL, | |
200 value NUMBER(38,2), | |
201 gauge_id NUMBER(38,0), | |
202 named_value_id NUMBER(38,0), | |
203 time_interval_id NUMBER(38,0), | |
204 PRIMARY KEY (id) | |
205 ); | |
206 | |
207 | |
208 -- NAMED_MAIN_VALUES | |
209 CREATE SEQUENCE NAMED_MAIN_VALUES_ID_SEQ; | |
210 | |
211 CREATE TABLE named_main_values ( | |
212 id NUMBER(38,0) NOT NULL, | |
213 name VARCHAR2(255), | |
214 type_id NUMBER(38,0), | |
215 PRIMARY KEY (id) | |
216 ); | |
217 | |
218 | |
219 -- POSITIONS | |
220 CREATE SEQUENCE POSITIONS_ID_SEQ; | |
221 | |
222 CREATE TABLE positions ( | |
223 id NUMBER(38,0) NOT NULL, | |
224 value VARCHAR2(255 char), | |
225 PRIMARY KEY (id) | |
226 ); | |
227 | |
228 | |
229 --- RANGES | |
230 CREATE SEQUENCE RANGES_ID_SEQ; | |
231 | |
232 CREATE TABLE ranges ( | |
233 id NUMBER(38,0) NOT NULL, | |
234 a NUMBER(38,10), | |
235 b NUMBER(38,10), | |
236 river_id NUMBER(38,0), | |
237 PRIMARY KEY (id) | |
238 ); | |
239 | |
240 | |
241 -- RIVERS | |
242 CREATE SEQUENCE RIVERS_ID_SEQ; | |
243 | |
244 CREATE TABLE rivers ( | |
245 id NUMBER(38,0) NOT NULL, | |
246 km_up NUMBER(38,0), | |
247 name VARCHAR2(255), | |
248 wst_unit_id NUMBER(38,0), | |
249 PRIMARY KEY (id) | |
250 ); | |
251 | |
252 | |
253 -- TIME_INTERVALS | |
254 CREATE SEQUENCE TIME_INTERVALS_ID_SEQ; | |
255 | |
256 CREATE TABLE time_intervals ( | |
257 id NUMBER(38,0) NOT NULL, | |
258 start_time TIMESTAMP, | |
259 stop_time TIMESTAMP, | |
260 PRIMARY KEY (id) | |
261 ); | |
262 | |
263 | |
264 --- UNITS | |
265 CREATE SEQUENCE UNITS_ID_SEQ; | |
266 | |
267 CREATE TABLE units ( | |
268 id NUMBER(38,0) NOT NULL, | |
269 name VARCHAR2(255), | |
270 PRIMARY KEY (id) | |
271 ); | |
272 | |
273 | |
274 -- WST_COLUMN_Q_RANGES | |
275 CREATE SEQUENCE WST_COLUMN_Q_RANGES_ID_SEQ; | |
276 | |
277 CREATE TABLE wst_column_q_ranges ( | |
278 id NUMBER(38,0) NOT NULL, | |
279 wst_column_id NUMBER(38,0), | |
280 wst_q_range_id NUMBER(38,0), | |
281 PRIMARY KEY (id) | |
282 ); | |
283 | |
284 | |
285 -- WST_COLUMN_VALUES | |
286 CREATE SEQUENCE WST_COLUMN_VALUES_ID_SEQ; | |
287 | |
288 CREATE TABLE wst_column_values ( | |
289 id NUMBER(38,0) NOT NULL, | |
290 position NUMBER(38,2), | |
291 w NUMBER(38,2), | |
292 wst_column_id NUMBER(38,0), | |
293 PRIMARY KEY (id) | |
294 ); | |
295 | |
296 | |
297 -- WST_COLUMNS | |
298 CREATE SEQUENCE WST_COLUMNS_ID_SEQ; | |
299 | |
300 CREATE TABLE wst_columns ( | |
301 id NUMBER(38,0) NOT NULL, | |
302 description VARCHAR2(255), | |
303 name VARCHAR2(255), | |
304 position NUMBER(38,0), | |
305 time_interval_id NUMBER(38,0), | |
306 wst_id NUMBER(38,0), | |
307 PRIMARY KEY (id) | |
308 ); | |
309 | |
310 | |
311 -- WST_Q_RANGES | |
312 CREATE SEQUENCE WST_Q_RANGES_ID_SEQ; | |
313 | |
314 CREATE TABLE wst_q_ranges ( | |
315 id NUMBER(38,0) NOT NULL, | |
316 q NUMBER(38,2), | |
317 range_id NUMBER(38,0), | |
318 PRIMARY KEY (id) | |
319 ); | |
320 | |
321 | |
322 -- WSTS | |
323 CREATE SEQUENCE WSTS_ID_SEQ; | |
324 | |
325 CREATE TABLE wsts ( | |
326 id NUMBER(38,0) NOT NULL, | |
327 description VARCHAR2(255), | |
328 kind NUMBER(38,0), | |
329 river_id NUMBER(38,0), | |
330 PRIMARY KEY (id) | |
331 ); | |
332 | |
333 | |
334 -- ADD CONSTRAINTs | |
335 ALTER TABLE annotations ADD CONSTRAINT cAnnotationsRanges FOREIGN KEY (range_id) REFERENCES ranges; | |
336 ALTER TABLE annotations ADD CONSTRAINT cAnnotationsEdges FOREIGN KEY (edge_id) REFERENCES edges; | |
337 ALTER TABLE annotations ADD CONSTRAINT cAnnotationsPositions FOREIGN KEY (position_id) REFERENCES positions; | |
338 ALTER TABLE annotations ADD CONSTRAINT cAnnotationsAttributes FOREIGN KEY (attribute_id) REFERENCES attributes; | |
339 ALTER TABLE annotations ADD CONSTRAINT cAnnotationsTypes FOREIGN KEY (type_id) REFERENCES annotation_types; | |
340 ALTER TABLE cross_section_lines ADD CONSTRAINT cQPSLinesCrossSections FOREIGN KEY (cross_section_id) REFERENCES cross_sections; | |
341 ALTER TABLE cross_section_points ADD CONSTRAINT cQPSPointsCrossSectionLines FOREIGN KEY (cross_section_line_id) REFERENCES cross_section_lines; | |
342 ALTER TABLE cross_sections ADD CONSTRAINT cCrossSectionsRivers FOREIGN KEY (river_id) REFERENCES rivers; | |
343 ALTER TABLE cross_sections ADD CONSTRAINT cCrossSectionsTimeIntervals FOREIGN KEY (time_interval_id) REFERENCES time_intervals; | |
344 ALTER TABLE discharge_table_values ADD CONSTRAINT cTableValuesDischargeTables foreign key (table_id) REFERENCES discharge_tables; | |
345 ALTER TABLE discharge_tables ADD CONSTRAINT cDischargeTablesTime_intervals FOREIGN KEY (time_interval_id) REFERENCES time_intervals; | |
346 ALTER TABLE discharge_tables ADD CONSTRAINT cDischargeTablesGauges FOREIGN KEY (gauge_id) REFERENCES gauges; | |
347 ALTER TABLE gauges ADD CONSTRAINT cGaugesRivers FOREIGN KEY (river_id) REFERENCES rivers; | |
348 ALTER TABLE gauges ADD CONSTRAINT cGaugesRanges FOREIGN KEY (range_id) REFERENCES ranges; | |
349 ALTER TABLE hyk_entries ADD CONSTRAINT cHykEntriesHyks FOREIGN KEY (hyk_id) REFERENCES hyks; | |
350 ALTER TABLE hyk_flow_zones ADD CONSTRAINT cHykFlowZonesHykFormations FOREIGN KEY (formation_id) REFERENCES hyk_formations; | |
351 ALTER TABLE hyk_flow_zones ADD CONSTRAINT cHykFlowZonesHykFlowZoneTypes FOREIGN KEY (type_id) REFERENCES hyk_flow_zone_types; | |
352 ALTER TABLE hyks ADD CONSTRAINT cHyksRivers FOREIGN KEY (river_id) REFERENCES rivers; | |
353 ALTER TABLE hyk_formations ADD CONSTRAINT cHykFormationsHykEntries FOREIGN KEY (hyk_entry_id) REFERENCES hyk_entries; | |
354 ALTER TABLE main_values ADD CONSTRAINT cMainValuesTimeIntervals FOREIGN KEY (time_interval_id) REFERENCES time_intervals; | |
355 ALTER TABLE main_values ADD CONSTRAINT cMainValuesGauges FOREIGN KEY (gauge_id) REFERENCES gauges; | |
356 ALTER TABLE main_values ADD CONSTRAINT cMainValuesNamedMainValues FOREIGN KEY (named_value_id) REFERENCES named_main_values; | |
357 ALTER TABLE named_main_values ADD CONSTRAINT cNamedMainValuesMainValueTypes FOREIGN KEY (type_id) REFERENCES main_value_types; | |
358 ALTER TABLE ranges ADD CONSTRAINT cRangesRivers FOREIGN KEY (river_id) REFERENCES rivers; | |
359 ALTER TABLE rivers ADD CONSTRAINT cRiversUnits FOREIGN KEY (wst_unit_id) REFERENCES units; | |
360 ALTER TABLE wst_column_q_ranges ADD CONSTRAINT cWstColumnQRangesWstColums FOREIGN KEY (wst_column_id) REFERENCES wst_columns; | |
361 ALTER TABLE wst_column_q_ranges ADD CONSTRAINT cWstColumnQRangesWstQRanges FOREIGN KEY (wst_q_range_id) REFERENCES wst_q_ranges; | |
362 ALTER TABLE wst_column_values ADD CONSTRAINT cWstColumnValuesWstColumns FOREIGN KEY (wst_column_id) REFERENCES wst_columns; | |
363 ALTER TABLE wst_columns ADD CONSTRAINT cWstColumnsTime_intervals FOREIGN KEY (time_interval_id) REFERENCES time_intervals; | |
364 ALTER TABLE wst_columns ADD CONSTRAINT cWstColumnsWsts FOREIGN KEY (wst_id) REFERENCES wsts; | |
365 ALTER TABLE wst_q_ranges ADD CONSTRAINT cWstQRangesRanges FOREIGN KEY (range_id) REFERENCES RANGES; | |
366 ALTER TABLE wsts ADD CONSTRAINT cWstsRivers FOREIGN KEY (river_id) REFERENCES rivers; | |
367 | |
368 -- VIEWS | |
369 | |
370 CREATE VIEW wst_value_table AS | |
371 SELECT wcv.position AS position, | |
372 w, | |
373 (SELECT q | |
374 FROM wst_column_q_ranges wcqr | |
375 JOIN wst_q_ranges wqr | |
376 ON wcqr.wst_q_range_id = wqr.id | |
377 JOIN ranges r | |
378 ON r.id = wqr.range_id | |
379 WHERE wcqr.wst_column_id = wc.id | |
380 AND wcv.position BETWEEN r.a AND r.b) AS q, | |
381 wc.position AS column_pos, | |
382 w.id AS wst_id | |
383 FROM wst_column_values wcv | |
384 JOIN wst_columns wc | |
385 ON wcv.wst_column_id = wc.id | |
386 JOIN wsts w | |
387 ON wc.wst_id = w.id | |
388 ORDER BY wcv.position ASC, | |
389 wc.position DESC; | |
390 | |
391 -- view to select the w values of a WST | |
392 CREATE VIEW wst_w_values AS | |
393 SELECT wcv.position AS km, | |
394 wcv.w AS w, | |
395 wc.position AS column_pos, | |
396 w.id AS wst_id | |
397 FROM wst_column_values wcv | |
398 JOIN wst_columns wc ON wcv.wst_column_id = wc.id | |
399 JOIN wsts w ON wc.wst_id = w.id | |
400 ORDER BY wcv.position, wc.position; | |
401 | |
402 -- view to select the q values of a WST | |
403 CREATE VIEW wst_q_values AS | |
404 SELECT wc.position AS column_pos, | |
405 wqr.q AS q, | |
406 r.a AS a, | |
407 r.b AS b, | |
408 wc.wst_id AS wst_id | |
409 FROM wst_column_q_ranges wcqr | |
410 JOIN wst_q_ranges wqr ON wcqr.wst_q_range_id = wqr.id | |
411 JOIN ranges r ON wqr.range_id = r.id | |
412 JOIN wst_columns wc ON wcqr.wst_column_id = wc.id | |
413 ORDER BY wc.position, wcqr.wst_column_id, r.a; |