Skill 1.2.5
Create triggers
Key Concepts
DML triggers fire for INSERT, UPDATE or DELETE. An AFTER trigger runs after the statement and its constraints succeed and can roll back the transaction; an INSTEAD OF trigger replaces the statement, which makes multi-table views updatable. A trigger fires once per statement, not per row, and reads the affected rows from the inserted and deleted pseudo-tables, so its logic must be set-based. UPDATE(column) tells whether a column was in the SET list.
DDL triggers fire for events such as CREATE_TABLE, ALTER_PROCEDURE or the DDL_DATABASE_LEVEL_EVENTS group, and EVENTDATA() returns XML that describes the event. Because triggers run inside the caller's transaction, a slow trigger, such as one that calls an external service, slows every write and can cause blocking. Constraints, computed columns and temporal tables are often simpler than triggers for the same goal.