Mercurial > dive4elements > river
view flys-backend/doc/schema/oracle.sql @ 2353:67e0371f6f40
Adjusted NUMBER format for units, positions and cross_section_points tables.
flys-backend/trunk@2986 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Schilberg <bjoern@intevation.de> |
---|---|
date | Mon, 17 Oct 2011 12:10:12 +0000 |
parents | 8126ccb58f28 |
children | 40093215061b |
line wrap: on
line source
-- ANNOTATION_TYPES CREATE SEQUENCE ANNOTATION_TYPES_ID_SEQ; CREATE TABLE annotation_types ( id NUMBER(38,0) NOT NULL, name VARCHAR2(255), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER annotation_types_trigger BEFORE INSERT ON annotation_types FOR each ROW BEGIN SELECT ANNOTATION_TYPES_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- ANNOTATIONS CREATE SEQUENCE ANNOTATIONS_ID_SEQ; CREATE TABLE annotations ( id NUMBER(38,0) NOT NULL, attribute_id NUMBER(38,0), edge_id NUMBER(38,0), position_id NUMBER(38,0), range_id NUMBER(38,0), type_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER annotations_trigger BEFORE INSERT ON annotations FOR each ROW BEGIN SELECT ANNOTATIONS_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- ATTRIBUTES CREATE SEQUENCE ATTRIBUTES_ID_SEQ; CREATE TABLE attributes ( id NUMBER(38,0) NOT NULL, value VARCHAR2(255), primary key (id) ); CREATE OR REPLACE TRIGGER attributes_trigger BEFORE INSERT ON attributes FOR each ROW BEGIN SELECT ATTRIBUTES_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- CROSS_SECTION_LINES CREATE SEQUENCE CROSS_SECTION_LINES_ID_SEQ; CREATE TABLE cross_section_lines ( id NUMBER(38,0) NOT NULL, km NUMBER(38,2), cross_section_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER cross_section_lines_trigger BEFORE INSERT ON cross_section_lines FOR each ROW BEGIN SELECT CROSS_SECTION_LINES_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- CROSS_SECTION_POINTS CREATE SEQUENCE CROSS_SECTION_POINTS_ID_SEQ; CREATE TABLE cross_section_points ( id NUMBER(38,0) NOT NULL, col_pos NUMBER(38,0), x NUMBER(38,2), y NUMBER(38,2), cross_section_line_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER cross_section_points_trigger BEFORE INSERT ON cross_section_points FOR each ROW BEGIN SELECT CROSS_SECTION_POINTS_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- CROSS_SECTIONS create sequence CROSS_SECTIONS_ID_SEQ; create table cross_sections ( id NUMBER(38,0) NOT NULL, description VARCHAR2(255), river_id NUMBER(38,0), time_interval_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER cross_sections_trigger BEFORE INSERT ON cross_sections FOR each ROW BEGIN SELECT CROSS_SECTIONS_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- DISCHARGE_TABLE_VALUES CREATE SEQUENCE DISCHARGE_TABLE_VALUES_ID_SEQ; CREATE TABLE discharge_table_values ( id NUMBER(38,0) NOT NULL, q NUMBER(38,2), w NUMBER(38,2), table_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER discharge_table_values_trigger BEFORE INSERT ON discharge_table_values FOR each ROW BEGIN SELECT DISCHARGE_TABLE_VALUES_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- DISCHARGE_TABLES CREATE SEQUENCE DISCHARGE_TABLES_ID_SEQ; CREATE TABLE discharge_tables ( id NUMBER(38,0) NOT NULL, description VARCHAR2(255), kind NUMBER(38,0), gauge_id NUMBER(38,0), time_interval_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER discharge_tables_trigger BEFORE INSERT ON discharge_tables FOR each ROW BEGIN SELECT DISCHARGE_TABLES_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- EDGES CREATE SEQUENCE EDGES_ID_SEQ; CREATE TABLE edges ( id NUMBER(38,0) NOT NULL, bottom NUMBER(38,2), top NUMBER(38,2), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER edges_trigger BEFORE INSERT ON edges FOR each ROW BEGIN SELECT EDGES_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- GAUGES CREATE SEQUENCE GAUGES_ID_SEQ; CREATE TABLE gauges ( id NUMBER(38,0) NOT NULL, aeo NUMBER(38,2), datum NUMBER(38,2), name VARCHAR2(255), station NUMBER(38,2), range_id NUMBER(38,0), river_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER gauges_trigger BEFORE INSERT ON gauges FOR each ROW BEGIN SELECT GAUGES_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- HYK_ENTRIES CREATE SEQUENCE HYK_ENTRIES_ID_SEQ; CREATE TABLE hyk_entries ( id NUMBER(38,0) NOT NULL, km NUMBER(38,2), measure TIMESTAMP, hyk_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER hyk_entries_trigger BEFORE INSERT ON hyk_entries FOR each ROW BEGIN SELECT HYK_ENTRIES_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- HYK_FLOW_ZONE_TYPES CREATE SEQUENCE HYK_FLOW_ZONE_TYPES_ID_SEQ; CREATE TABLE hyk_flow_zone_types ( id NUMBER(38,0) NOT NULL, description VARCHAR2(255), name VARCHAR2(255), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER hyk_flow_zone_types_trigger BEFORE INSERT ON hyk_flow_zone_types FOR each ROW BEGIN SELECT HYK_FLOW_ZONE_TYPES_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- HYK_FLOW_ZONES CREATE SEQUENCE HYK_FLOW_ZONES_ID_SEQ; CREATE TABLE hyk_flow_zones ( id NUMBER(38,0) NOT NULL, a NUMBER(38,2), b NUMBER(38,2), formation_id NUMBER(38,0), type_id NUMBER(38,0), primary key (id) ); CREATE OR REPLACE TRIGGER hyk_flow_zones_trigger BEFORE INSERT ON hyk_flow_zones FOR each ROW BEGIN SELECT HYK_FLOW_ZONES_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- HYK_FORMATIONS CREATE SEQUENCE HYK_FORMATIONS_ID_SEQ; CREATE TABLE hyk_formations ( id NUMBER(38,0) NOT NULL, bottom NUMBER(38,2), distance_hf NUMBER(38,2), distance_vl NUMBER(38,2), distance_vr NUMBER(38,2), formation_num NUMBER(38,0), top NUMBER(38,2), hyk_entry_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER hyk_formations_trigger BEFORE INSERT ON hyk_formations FOR each ROW BEGIN SELECT HYK_FORMATIONS_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- HYKS CREATE SEQUENCE HYKS_ID_SEQ; CREATE TABLE hyks ( id NUMBER(38,0) NOT NULL, description VARCHAR2(255), river_id NUMBER(38,0), primary key (id) ); CREATE OR REPLACE TRIGGER hyks_trigger BEFORE INSERT ON hyks FOR each ROW BEGIN SELECT HYKS_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- MAIN_VALUE_TYPES CREATE SEQUENCE MAIN_VALUE_TYPES_ID_SEQ; CREATE TABLE main_value_types ( id NUMBER(38,0) NOT NULL, name VARCHAR2(255), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER main_value_types_trigger BEFORE INSERT ON main_value_types FOR each ROW BEGIN SELECT MAIN_VALUE_TYPES_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- MAIN_VALUES CREATE SEQUENCE MAIN_VALUES_ID_SEQ; CREATE TABLE main_values ( id NUMBER(38,0) NOT NULL, value NUMBER(38,2), gauge_id NUMBER(38,0), named_value_id NUMBER(38,0), time_interval_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER main_values_trigger BEFORE INSERT ON main_values FOR each ROW BEGIN SELECT MAIN_VALUES_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- NAMED_MAIN_VALUES CREATE SEQUENCE NAMED_MAIN_VALUES_ID_SEQ; CREATE TABLE named_main_values ( id NUMBER(38,0) NOT NULL, name VARCHAR2(255), type_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER named_main_values_trigger BEFORE INSERT ON named_main_values FOR each ROW BEGIN SELECT NAMED_MAIN_VALUES_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- POSITIONS CREATE SEQUENCE POSITIONS_ID_SEQ; CREATE TABLE positions ( id NUMBER(38,0) NOT NULL, value VARCHAR2(255 char), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER positions_trigger BEFORE INSERT ON positions FOR each ROW BEGIN SELECT POSITIONS_ID_SEQ.nextval INTO :new.id FROM dual; END; / --- RANGES CREATE SEQUENCE RANGES_ID_SEQ; CREATE TABLE ranges ( id NUMBER(38,0) NOT NULL, a NUMBER(38,2), b NUMBER(38,2), river_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER ranges_trigger BEFORE INSERT ON ranges FOR each ROW BEGIN SELECT RANGES_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- RIVERS CREATE SEQUENCE RIVERS_ID_SEQ; CREATE TABLE rivers ( id NUMBER(38,0) NOT NULL, km_up NUMBER(38,0), name VARCHAR2(255), wst_unit_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER rivers_trigger BEFORE INSERT ON rivers FOR each ROW BEGIN SELECT RIVERS_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- TIME_INTERVALS CREATE SEQUENCE TIME_INTERVALS_ID_SEQ; CREATE TABLE time_intervals ( id NUMBER(38,0) NOT NULL, start_time TIMESTAMP, stop_time TIMESTAMP, PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER time_intervals_trigger BEFORE INSERT ON time_intervals FOR each ROW BEGIN SELECT TIME_INTERVALS_ID_SEQ.nextval INTO :new.id FROM dual; END; / --- UNITS CREATE SEQUENCE UNITS_ID_SEQ; CREATE TABLE units ( id NUMBER(38,0) NOT NULL, name VARCHAR2(255), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER units_trigger BEFORE INSERT ON units FOR each ROW BEGIN SELECT UNITS_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- WST_COLUMN_Q_RANGES CREATE SEQUENCE WST_COLUMN_Q_RANGES_ID_SEQ; CREATE TABLE wst_column_q_ranges ( id NUMBER(38,0) NOT NULL, wst_column_id NUMBER(38,0), wst_q_range_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER wst_column_q_ranges_trigger BEFORE INSERT ON wst_column_q_ranges FOR each ROW BEGIN SELECT WST_COLUMN_Q_RANGES_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- WST_COLUMN_VALUES CREATE SEQUENCE WST_COLUMN_VALUES_ID_SEQ; CREATE TABLE wst_column_values ( id NUMBER(38,0) NOT NULL, position NUMBER(38,2), w NUMBER(38,2), wst_column_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER wst_column_values_trigger BEFORE INSERT ON wst_column_values FOR each ROW BEGIN SELECT WST_COLUMN_VALUES_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- WST_COLUMNS CREATE SEQUENCE WST_COLUMNS_ID_SEQ; CREATE TABLE wst_columns ( id NUMBER(38,0) NOT NULL, description VARCHAR2(255), name VARCHAR2(255), position NUMBER(38,0), time_interval_id NUMBER(38,0), wst_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER wst_columns_trigger BEFORE INSERT ON wst_columns FOR each ROW BEGIN SELECT WST_COLUMNS_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- WST_Q_RANGES CREATE SEQUENCE WST_Q_RANGES_ID_SEQ; CREATE TABLE wst_q_ranges ( id NUMBER(38,0) NOT NULL, q NUMBER(38,2), range_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER wst_q_ranges_trigger BEFORE INSERT ON wst_q_ranges FOR each ROW BEGIN SELECT WST_Q_RANGES_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- WSTS CREATE SEQUENCE WSTS_ID_SEQ; CREATE TABLE wsts ( id NUMBER(38,0) NOT NULL, description VARCHAR2(255), kind NUMBER(38,0), river_id NUMBER(38,0), PRIMARY KEY (id) ); CREATE OR REPLACE TRIGGER wsts_trigger BEFORE INSERT ON wsts FOR each ROW BEGIN SELECT WSTS_ID_SEQ.nextval INTO :new.id FROM dual; END; / -- ADD CONSTRAINTs ALTER TABLE annotations ADD CONSTRAINT cAnnotationsRanges FOREIGN KEY (range_id) REFERENCES ranges; ALTER TABLE annotations ADD CONSTRAINT cAnnotationsEdges FOREIGN KEY (edge_id) REFERENCES edges; ALTER TABLE annotations ADD CONSTRAINT cAnnotationsPositions FOREIGN KEY (position_id) REFERENCES positions; ALTER TABLE annotations ADD CONSTRAINT cAnnotationsAttributes FOREIGN KEY (attribute_id) REFERENCES attributes; ALTER TABLE annotations ADD CONSTRAINT cAnnotationsTypes FOREIGN KEY (type_id) REFERENCES annotation_types; ALTER TABLE cross_section_lines ADD CONSTRAINT cQPSLinesCrossSections FOREIGN KEY (cross_section_id) REFERENCES cross_sections; ALTER TABLE cross_section_points ADD CONSTRAINT cQPSPointsCrossSectionLines FOREIGN KEY (cross_section_line_id) REFERENCES cross_section_lines; ALTER TABLE cross_sections ADD CONSTRAINT cCrossSectionsRivers FOREIGN KEY (river_id) REFERENCES rivers; ALTER TABLE cross_sections ADD CONSTRAINT cCrossSectionsTimeIntervals FOREIGN KEY (time_interval_id) REFERENCES time_intervals; ALTER TABLE discharge_table_values ADD CONSTRAINT cTableValuesDischargeTables foreign key (table_id) REFERENCES discharge_tables; ALTER TABLE discharge_tables ADD CONSTRAINT cDischargeTablesTime_intervals FOREIGN KEY (time_interval_id) REFERENCES time_intervals; ALTER TABLE discharge_tables ADD CONSTRAINT cDischargeTablesGauges FOREIGN KEY (gauge_id) REFERENCES gauges; ALTER TABLE gauges ADD CONSTRAINT cGaugesRivers FOREIGN KEY (river_id) REFERENCES rivers; ALTER TABLE gauges ADD CONSTRAINT cGaugesRanges FOREIGN KEY (range_id) REFERENCES ranges; ALTER TABLE hyk_entries ADD CONSTRAINT cHykEntriesHyks FOREIGN KEY (hyk_id) REFERENCES hyks; ALTER TABLE hyk_flow_zones ADD CONSTRAINT cHykFlowZonesHykFormations FOREIGN KEY (formation_id) REFERENCES hyk_formations; ALTER TABLE hyk_flow_zones ADD CONSTRAINT cHykFlowZonesHykFlowZoneTypes FOREIGN KEY (type_id) REFERENCES hyk_flow_zone_types; ALTER TABLE hyks ADD CONSTRAINT cHyksRivers FOREIGN KEY (river_id) REFERENCES rivers; ALTER TABLE hyk_formations ADD CONSTRAINT cHykFormationsHykEntries FOREIGN KEY (hyk_entry_id) REFERENCES hyk_entries; ALTER TABLE main_values ADD CONSTRAINT cMainValuesTimeIntervals FOREIGN KEY (time_interval_id) REFERENCES time_intervals; ALTER TABLE main_values ADD CONSTRAINT cMainValuesGauges FOREIGN KEY (gauge_id) REFERENCES gauges; ALTER TABLE main_values ADD CONSTRAINT cMainValuesNamedMainValues FOREIGN KEY (named_value_id) REFERENCES named_main_values; ALTER TABLE named_main_values ADD CONSTRAINT cNamedMainValuesMainValueTypes FOREIGN KEY (type_id) REFERENCES main_value_types; ALTER TABLE ranges ADD CONSTRAINT cRangesRivers FOREIGN KEY (river_id) REFERENCES rivers; ALTER TABLE rivers ADD CONSTRAINT cRiversUnits FOREIGN KEY (wst_unit_id) REFERENCES units; ALTER TABLE wst_column_q_ranges ADD CONSTRAINT cWstColumnQRangesWstColums FOREIGN KEY (wst_column_id) REFERENCES wst_columns; ALTER TABLE wst_column_q_ranges ADD CONSTRAINT cWstColumnQRangesWstQRanges FOREIGN KEY (wst_q_range_id) REFERENCES wst_q_ranges; ALTER TABLE wst_column_values ADD CONSTRAINT cWstColumnValuesWstColumns FOREIGN KEY (wst_column_id) REFERENCES wst_columns; ALTER TABLE wst_columns ADD CONSTRAINT cWstColumnsTime_intervals FOREIGN KEY (time_interval_id) REFERENCES time_intervals; ALTER TABLE wst_columns ADD CONSTRAINT cWstColumnsWsts FOREIGN KEY (wst_id) REFERENCES wsts; ALTER TABLE wst_q_ranges ADD CONSTRAINT cWstQRangesRanges FOREIGN KEY (range_id) REFERENCES RANGES; ALTER TABLE wsts ADD CONSTRAINT cWstsRivers FOREIGN KEY (river_id) REFERENCES rivers;