-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrigger.sql
More file actions
42 lines (36 loc) · 1 KB
/
Trigger.sql
File metadata and controls
42 lines (36 loc) · 1 KB
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
SET SERVEROUTPUT ON
CREATE OR REPLACE TRIGGER trigdel
BEFORE delete ON reservation
REFERENCING OLD AS o NEW AS n
FOR EACH ROW
BEGIN
delete from transaction where reservation_id=:o.id;
delete from train_ticket where id=:o.ticket_id;
END;
/
delete from reservation where id = 2;
SET SERVEROUTPUT ON
CREATE OR REPLACE TRIGGER trigup
after update ON train_ticket
REFERENCING OLD AS o NEW AS n
FOR EACH ROW
Enable
BEGIN
update reservation set ticket_id=:n.id where ticket_id = :o.id;
END;
/
update train_ticket set id = 9 where id = 5;
SET SERVEROUTPUT ON
CREATE OR REPLACE TRIGGER trignew
after insert ON transaction
REFERENCING OLD AS o NEW AS n
FOR EACH ROW
Declare
BEGIN
insert into reservation values (:n.reservation_id, null , :n.admin_id , :n.customer_id , TO_DATE('2099-12-31', 'YYYY-MM-DD'), 'NIL', 'Unknown');
END;
/
INSERT INTO Transaction VALUES (11, 1, 100, 20, 2, 2, TO_DATE('2023-04-20', 'YYYY-MM-DD'));
drop trigger trigdel;
drop trigger trigup;
drop trigger trignew;