1-- SQL Server (update my_table2 after insert on my_table1)
2CREATE TRIGGER trigger_name ON my_table1 FOR INSERT AS
3BEGIN
4 UPDATE my_table2 SET my_col_date = getdate() FROM my_table1
5END
6-- Oracle (insert into log table after update on my_table)
7CREATE OR REPLACE TRIGGER trigger_name AFTER INSERT ON my_table
8FOR EACH ROW
9BEGIN
10 INSERT INTO my_log_table (LOG_DATE, ACTION) VALUES (SYSDATE, 'Changed');
11END;
1CREATE TRIGGER trigger_name
2ON { Table name or view name }
3[ WITH <Options> ]
4{ FOR | AFTER | INSTEAD OF }
5{ [INSERT], [UPDATE] , [DELETE] }
1
2
3
4
5 CREATE TRIGGER trigger_name
6 BEFORE INSERT
7 ON table_name FOR EACH ROW
8trigger_body;
9
1
2
3
4
5 DELIMITER $$
6
7CREATE TRIGGER before_workcenters_insert
8BEFORE INSERT
9ON WorkCenters FOR EACH ROW
10BEGIN
11 DECLARE rowcount INT;
12
13 SELECT COUNT(*)
14 INTO rowcount
15 FROM WorkCenterStats;
16
17 IF rowcount > 0 THEN
18 UPDATE WorkCenterStats
19 SET totalCapacity = totalCapacity + new.capacity;
20 ELSE
21 INSERT INTO WorkCenterStats(totalCapacity)
22 VALUES(new.capacity);
23 END IF;
24
25END $$
26
27DELIMITER ;
28