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;
1CREATE TRIGGER Product_Details_tr
2BEFORE INSERT ON Product_Details
3FOR EACH ROW
4SET NEW.User_ID = CURRENT_USER();
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);
1-- SQL Server Syntax
2-- Trigger on an INSERT, UPDATE, or DELETE statement to a table or view (DML Trigger)
3
4CREATE [ OR ALTER ] TRIGGER [ schema_name . ]trigger_name
5ON { table | view }
6[ WITH <dml_trigger_option> [ ,...n ] ]
7{ FOR | AFTER | INSTEAD OF }
8{ [ INSERT ] [ , ] [ UPDATE ] [ , ] [ DELETE ] }
9[ WITH APPEND ]
10[ NOT FOR REPLICATION ]
11AS { sql_statement [ ; ] [ ,...n ] | EXTERNAL NAME <method specifier [ ; ] > }
12
13<dml_trigger_option> ::=
14 [ ENCRYPTION ]
15 [ EXECUTE AS Clause ]
16
17<method_specifier> ::=
18 assembly_name.class_name.method_name
19
20
1CREATE TRIGGER [schema_name.]trigger_name
2ON table_name
3{FOR | AFTER | INSTEAD OF} {[INSERT] [,] [UPDATE] [,] [DELETE]}
4AS
5{sql_statements}
1-- Azure SQL Database Syntax
2-- Trigger on an INSERT, UPDATE, or DELETE statement to a table or view (DML Trigger)
3
4CREATE [ OR ALTER ] TRIGGER [ schema_name . ]trigger_name
5ON { table | view }
6 [ WITH <dml_trigger_option> [ ,...n ] ]
7{ FOR | AFTER | INSTEAD OF }
8{ [ INSERT ] [ , ] [ UPDATE ] [ , ] [ DELETE ] }
9 AS { sql_statement [ ; ] [ ,...n ] [ ; ] > }
10
11<dml_trigger_option> ::=
12 [ EXECUTE AS Clause ]
13
14