IT lexicon › Database › Trigger (DB)

Trigger (DB)

Database På svenska → Updated: 2026-07-30

DB procedure that runs automatically on INSERT/UPDATE/DELETE. BEFORE/AFTER + ROW/STATEMENT level. Use: audit logs (who changed what), denormalization, derived columns, business rules.

PostgreSQL: trigger calls a function (PL/pgSQL, PL/Python, etc). MySQL: inline trigger body. Trade-offs: triggers hide logic — "why does this column change?" → not in app code, you have to dig through the DB schema. Performance: heavy triggers make simple UPDATEs slow. Modern alternative: CDC + application-side handler for decoupling. Classic anti-pattern: a trigger that calls another UPDATE that fires another trigger → recursive explosion. Modern best practice: avoid triggers for business logic, OK for audit trails.

← Back to the lexicon