-
Notifications
You must be signed in to change notification settings - Fork 0
/
TRIGGER_autoincrement_create.sql
241 lines (216 loc) · 5.18 KB
/
TRIGGER_autoincrement_create.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
--********************************************************************
--*
--* Trigger: tr_autoincr_name_id_seq
--* Type: Before row
--* Type Extension: insert
--* Developer: Lukas Schweinberger
--* Description: Takes care of the continuation of IDs that are used as primary keys and increments it by 1
--*
--********************************************************************
CREATE OR REPLACE TRIGGER tr_autoincr_zug_id_seq
BEFORE INSERT ON zug
FOR EACH ROW
BEGIN
IF :NEW.zugID IS NULL THEN
SELECT zug_id_seq.NEXTVAL
INTO :new.zugID
FROM dual;
END IF;
END;
/
CREATE OR REPLACE TRIGGER tr_autoincr_wagon_art_id_seq
BEFORE INSERT ON wagon_art
FOR EACH ROW
BEGIN
IF :NEW.wagon_artID IS NULL THEN
SELECT wagon_art_id_seq.NEXTVAL
INTO :new.wagon_artID
FROM dual;
END IF;
END;
/
CREATE OR REPLACE TRIGGER tr_autoincr_wagon_id_seq
BEFORE INSERT ON wagon
FOR EACH ROW
BEGIN
IF :new.wagonID IS NULL THEN
SELECT wagon_id_seq.NEXTVAL
INTO :new.wagonID
FROM dual;
END IF;
END;
/
CREATE OR REPLACE TRIGGER tr_autoincr_lokomotive_id_seq
BEFORE INSERT ON lokomotive
FOR EACH ROW
BEGIN
IF :new.lokomotivID IS NULL THEN
SELECT lokomotive_id_seq.NEXTVAL
INTO :new.lokomotivID
FROM dual;
END IF;
END;
/
CREATE OR REPLACE TRIGGER tr_autoincr_allergen_id_seq
BEFORE INSERT ON allergen
FOR EACH ROW
BEGIN
IF :new.allergenID IS NULL THEN
SELECT allergen_id_seq.NEXTVAL
INTO :new.allergenID
FROM dual;
END IF;
END;
/
CREATE OR REPLACE TRIGGER tr_autoincr_produkt_id_seq
BEFORE INSERT ON produkt
FOR EACH ROW
BEGIN
IF :new.produktID IS NULL THEN
SELECT produkt_id_seq.NEXTVAL
INTO :new.produktID
FROM dual;
END IF;
END;
/
CREATE OR REPLACE TRIGGER tr_autoincr_person_id_seq
BEFORE INSERT ON person
FOR EACH ROW
BEGIN
IF :new.personID IS NULL THEN
SELECT person_id_seq.NEXTVAL
INTO :new.personID
FROM dual;
END IF;
END;
/
CREATE OR REPLACE TRIGGER tr_autoincr_bahnhof_id_seq
BEFORE INSERT ON bahnhof
FOR EACH ROW
BEGIN
IF :new.bahnhofID IS NULL THEN
SELECT bahnhof_id_seq.NEXTVAL
INTO :new.bahnhofID
FROM dual;
END IF;
END;
/
CREATE OR REPLACE TRIGGER tr_autoincr_bahnsteig_id_seq
BEFORE INSERT ON bahnsteig
FOR EACH ROW
BEGIN
IF :new.bahnsteigID IS NULL THEN
SELECT bahnsteig_id_seq.NEXTVAL
INTO :new.bahnsteigID
FROM dual;
END IF;
END;
/
CREATE OR REPLACE TRIGGER tr_autoincr_mrolle_id_seq
BEFORE INSERT ON mitarbeiter_rolle
FOR EACH ROW
BEGIN
IF :new.rollenID IS NULL THEN
SELECT mitarbeiter_rolle_id_seq.NEXTVAL
INTO :new.rollenID
FROM dual;
END IF;
END;
/
CREATE OR REPLACE TRIGGER tr_autoincr_gstufe_id_seq
BEFORE INSERT ON gehaltsstufe
FOR EACH ROW
BEGIN
IF :new.gehaltsstufeID IS NULL THEN
SELECT gehaltsstufe_id_seq.NEXTVAL
INTO :new.gehaltsstufeID
FROM dual;
END IF;
END;
/
CREATE OR REPLACE TRIGGER tr_autoincr_servicedesk_id_seq
BEFORE INSERT ON servicedesk
FOR EACH ROW
BEGIN
IF :new.servicedeskID IS NULL THEN
SELECT servicedesk_id_seq.NEXTVAL
INTO :new.servicedeskID
FROM dual;
END IF;
END;
/
CREATE OR REPLACE TRIGGER tr_autoincr_verbindung_id_seq
BEFORE INSERT ON verbindung
FOR EACH ROW
BEGIN
IF :new.verbindungID IS NULL THEN
SELECT verbindung_id_seq.NEXTVAL
INTO :new.verbindungID
FROM dual;
END IF;
END;
/
CREATE OR REPLACE TRIGGER tr_autoincr_wartung_id_seq
BEFORE INSERT ON wartung
FOR EACH ROW
BEGIN
IF :new.wartungsID IS NULL THEN
SELECT wartung_id_seq.NEXTVAL
INTO :new.wartungsID
FROM dual;
END IF;
END;
/
CREATE OR REPLACE TRIGGER tr_autoincr_ticket_art_id_seq
BEFORE INSERT ON ticket_art
FOR EACH ROW
BEGIN
IF :new.ticket_artID IS NULL THEN
SELECT ticket_art_id_seq.NEXTVAL
INTO :new.ticket_artID
FROM dual;
END IF;
END;
/
CREATE OR REPLACE TRIGGER tr_autoincr_ticket_id_seq
BEFORE INSERT ON ticket
FOR EACH ROW
BEGIN
IF :new.ticketID IS NULL THEN
SELECT ticket_id_seq.NEXTVAL
INTO :new.ticketID
FROM dual;
END IF;
END;
/
CREATE OR REPLACE TRIGGER tr_autoincr_artikel_id_seq
BEFORE INSERT ON online_artikel
FOR EACH ROW
BEGIN
IF :new.artikelID IS NULL THEN
SELECT artikel_id_seq.NEXTVAL
INTO :new.artikelID
FROM dual;
END IF;
END;
/
BEGIN
EXECUTE IMMEDIATE 'DROP TRIGGER tr_autoincr_zug_id_seq ';
EXECUTE IMMEDIATE 'DROP TRIGGER tr_autoincr_wagon_art_id_seq';
EXECUTE IMMEDIATE 'DROP TRIGGER tr_autoincr_wagon_id_seq ';
EXECUTE IMMEDIATE 'DROP TRIGGER tr_autoincr_lokomotive_id_seq';
EXECUTE IMMEDIATE 'DROP TRIGGER tr_autoincr_allergen_id_seq';
EXECUTE IMMEDIATE 'DROP TRIGGER tr_autoincr_produkt_id_seq';
EXECUTE IMMEDIATE 'DROP TRIGGER tr_autoincr_person_id_seq';
EXECUTE IMMEDIATE 'DROP TRIGGER tr_autoincr_bahnhof_id_seq';
EXECUTE IMMEDIATE 'DROP TRIGGER tr_autoincr_bahnsteig_id_seq';
EXECUTE IMMEDIATE 'DROP TRIGGER tr_autoincr_mrolle_id_seq ';
EXECUTE IMMEDIATE 'DROP TRIGGER tr_autoincr_gstufe_id_seq';
EXECUTE IMMEDIATE 'DROP TRIGGER tr_autoincr_servicedesk_id_seq';
EXECUTE IMMEDIATE 'DROP TRIGGER tr_autoincr_verbindung_id_seq';
EXECUTE IMMEDIATE 'DROP TRIGGER tr_autoincr_wartung_id_seq';
EXECUTE IMMEDIATE 'DROP TRIGGER tr_autoincr_ticket_art_id_seq';
EXECUTE IMMEDIATE 'DROP TRIGGER tr_autoincr_ticket_id_seq';
EXECUTE IMMEDIATE 'DROP TRIGGER tr_autoincr_artikel_id_seq';
END;
/