14. Triggers
Triggers run automatically when changes occur. They are useful for enforcing rules close to the data, but they can also make behavior harder to reason about if overused.
Decision Guide
| Need | Prefer | Notes |
|---|---|---|
| Audit changes | AFTER trigger | Write to an audit table |
| Validate data beyond constraints | BEFORE trigger | Prefer constraints when possible |
| Maintain derived columns (e.g., updated_at) | BEFORE UPDATE trigger | Keep it small and deterministic |
Lessons
What's Next
- Continue to 15. Scheduling and Automation