sql a trigger code example
Example 1: CREATE trigger SQL
CREATE OR REPLACE TRIGGER {trigger_name}
BEFORE | AFTER
INSERT | UPDATE | DELETE
ON {table_name}
(FOR EACH ROW)
{operation to be executed}
CREATE TRIGGER log_updates
AFTER INSERT OR UPDATE ON Person
FOR EACH ROW
INSERT INTO LogPerson(ts, IdPerson, surname)
VALUES(CURRENT_TIMESTAMP, NEW.id, NEW.surname);
Example 2: what is a trigger in sql
CREATE [ OR ALTER ] TRIGGER [ schema_name . ]trigger_name
ON { table | view }
[ WITH <dml_trigger_option> [ ,...n ] ]
{ FOR | AFTER | INSTEAD OF }
{ [ INSERT ] [ , ] [ UPDATE ] [ , ] [ DELETE ] }
[ WITH APPEND ]
[ NOT FOR REPLICATION ]
AS { sql_statement [ ; ] [ ,...n ] | EXTERNAL NAME <method specifier [ ; ] > }
<dml_trigger_option> ::=
[ ENCRYPTION ]
[ EXECUTE AS Clause ]
<method_specifier> ::=
assembly_name.class_name.method_name