Creating Triggers
Like all other objects in SQL Server, triggers are created through a CREATE statement. As you might suspect, this is actually a CREATE TRIGGER statement. The actual syntax for the CREATE TRIGGER statement is as follows:
CREATE TRIGGER trigger_name ON {table | view} [WITH ENCRYPTION] { {{FOR | AFTER | INSTEAD OF} { [DELETE] [,] [INSERT] [,] [UPDATE] } [WITH APPEND] [NOT FOR REPLICATION] AS { IF UPDATE (column) [{AND | OR} UPDATE (column)] [...n] | IF (COLUMNS_UPDATED() {bitwise_operator} updated_bitmask) { comparison_operator} column_bitmask [...n] } sql_statement [...n] }
Table 15.1 lists the syntax options available.
Option | Description |
---|---|
CREATE TRIGGER | Tells SQL Server that you're going to ... |
Get Writing Stored Procedures for Microsoft SQL Server now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.