Skip to content

Trigger

Spicy — senior dev territoryDatabase

ELI5 — The Vibe Check

A trigger is code that the database runs automatically when something happens — like automatically updating an 'updated_at' timestamp whenever a row changes. You do not call it manually; it fires by itself when the triggering event occurs.

Real Talk

A trigger is a database object that automatically executes a specified function in response to a data event (INSERT, UPDATE, DELETE) on a table. Triggers can run BEFORE or AFTER the event, and for each row affected or once per statement. They are used for auditing, enforcing complex constraints, and automatic field updates.

Show Me The Code

-- Auto-update updated_at timestamp
CREATE TRIGGER set_updated_at
BEFORE UPDATE ON users
FOR EACH ROW EXECUTE FUNCTION update_timestamp();

When You'll Hear This

"The trigger automatically sets updated_at when a row is modified." / "Too many triggers make it hard to trace what's happening in the database."

Made with passive-aggressive love by manoga.digital. Powered by Claude.