Trigger
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."
Related Terms
Function
A function is a reusable recipe. You write the steps once, give it a name, and call it whenever you need those steps done.
Stored Procedure
A stored procedure is a named program you write in SQL (and sometimes a procedural language) that lives inside the database.
Transaction
A transaction groups multiple database operations into one all-or-nothing bundle. Either ALL of them succeed, or NONE of them happen.