1-- SQL Server (update my_table after update on my_table)
2CREATE TRIGGER trigger_name ON my_table AFTER UPDATE AS
3IF UPDATE (col_name) -- Optional, for particular column
4BEGIN
5 UPDATE my_table SET my_col_date = getdate() FROM my_table
6END;
7-- Oracle (insert into log table after update on my_table)
8CREATE OR REPLACE TRIGGER trigger_name AFTER UPDATE ON my_table
9FOR EACH ROW
10BEGIN
11 INSERT INTO my_log_table (LOG_DATE, ACTION) VALUES (SYSDATE, 'Changed');
12END;
1-- Oracle DB Syntax
2CREATE OR REPLACE TRIGGER {trigger_name}
3BEFORE | AFTER
4INSERT | UPDATE | DELETE
5ON {table_name}
6(FOR EACH ROW)
7{operation to be executed}
8
9-- for example
10CREATE TRIGGER log_updates
11AFTER INSERT OR UPDATE ON Person
12FOR EACH ROW
13INSERT INTO LogPerson(ts, IdPerson, surname)
14VALUES(CURRENT_TIMESTAMP, NEW.id, NEW.surname);
1CREATE TRIGGER Product_Details_tr
2BEFORE INSERT ON Product_Details
3FOR EACH ROW
4SET NEW.User_ID = CURRENT_USER();
1CREATE TRIGGER trigger_name
2ON { Table name or view name }
3[ WITH <Options> ]
4{ FOR | AFTER | INSTEAD OF }
5{ [INSERT], [UPDATE] , [DELETE] }
1Syntax:
2create trigger [trigger_name]
3[before | after]
4{insert | update | delete}
5on [table_name]
6[for each row]
7as [print/select]
8Example:
9create trigger myDel
10on tbl_pro
11after delete
12as
13select * from tbl_product
14print 'Record Deleted successfully!!!'
1CREATE TRIGGER [schema_name.]trigger_name
2ON table_name
3{FOR | AFTER | INSTEAD OF} {[INSERT] [,] [UPDATE] [,] [DELETE]}
4AS
5{sql_statements}