Glossary

Trigger (DB)

A trigger is a database procedure that executes automatically in response to INSERT, UPDATE, or DELETE. No manual call needed — the DBMS fires it when a specific event occurs.

Example (MySQL)

CREATE TRIGGER after_order_insert
AFTER INSERT ON orders
FOR EACH ROW
BEGIN
  UPDATE users
  SET orders_count = orders_count + 1
  WHERE id = NEW.user_id;
END;

BEFORE vs AFTER

Use with caution

Triggers hide logic: an INSERT silently triggers a chain of changes in other tables. Hard to debug and invisible in application code. For most tasks, application-level event handlers are preferable.