What is a trigger in a relational database, and what are some appropriate use cases and pitfalls of using them?

Last updated 3 July 2026

  • A trigger is code the database runs automatically on INSERT/UPDATE/DELETE events (BEFORE, AFTER, or INSTEAD OF).

  • Good uses: audit logging, complex integrity rules constraints can't express, and maintaining derived or history tables.

  • Pitfalls: hidden logic that is hard to debug, added write latency, and cascading triggers. Prefer declarative constraints (CHECK, FOREIGN KEY) first.

  • https://dev.to/harshmange/when-to-use-database-triggers-and-how-they-work-5h9j
  • https://www.domo.com/glossary/database-triggers
  • https://www.codebegun.com/interview/sql/triggers
  • https://supabase.com/docs/guides/database/postgres/triggers
  • https://learn.microsoft.com/en-us/sql/relational-databases/triggers/dml-triggers?view=sql-server-ver17
  • https://medium.com/@adjetadjetey45/mastering-mysql-triggers-a-developers-guide-to-smarter-database-design-3f81abca2753
  • https://www.geeksforgeeks.org/sql/sql-trigger-student-database/
  • https://estuary.dev/blog/database-triggers/
All SQL interview questions