CREATE TRIGGER
defines a DML (AFTER/INSTEAD OF), DDL or logon trigger
What changes
- Input
- module body (its own statements and their sources)
- Output or change
- module definition
Syntax at a glance
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 [ ; ] > }
Work example
A table or view needs a reviewed response to a data or DDL event.
Test multi-row input, recursion, transaction effects, and error handling before approving the trigger.
Check your work One statement affecting several rows produces one correct set-based result.
Open Microsoft Learn for full syntax, permissions, and details for your version.