# Trigger

Code that runs automatically when a table's rows change.

## What is **Trigger**?

A **trigger** is code that runs automatically when rows are inserted, updated or deleted in a table, for example to write an audit log. Use them sparingly: they are easy to forget about.

```sql
CREATE TRIGGER dbo.Recipes_Audit ON dbo.Recipes AFTER UPDATE AS
BEGIN
    SET NOCOUNT ON;
    INSERT INTO dbo.AuditLog (Message, CreatedAt)
    SELECT CONCAT(N'Recipe changed: ', Title), SYSUTCDATETIME() FROM inserted;
END
```

Level: Journeyman · [More Database terms at this level](https://www.ask-codey.com/glossary/subjects/database/journeyman)

Updated: September 27, 2026

Source: https://www.ask-codey.com/glossary/trigger
