🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

Databases Intermediate

What is Trigger?

A database object that automatically executes a specified function when certain events (INSERT, UPDATE, DELETE) occur on a table.

Triggers run automatically in response to data changes. They can execute BEFORE or AFTER the triggering event, and operate on each row or once per statement. Common uses include audit logging, data validation, maintaining derived data, and enforcing complex business rules.

In PostgreSQL, triggers call trigger functions written in PL/pgSQL. While powerful, overuse of triggers can make database behavior hard to debug and predict. Consider application-level logic for complex business rules.

Related Terms

JSONB
PostgreSQL's binary JSON data type that stores JSON documents with indexing, querying, and manipulation capabilities.
Vacuum
A PostgreSQL maintenance operation that reclaims storage from dead tuples and updates statistics for the query planner.
Index
A data structure that improves the speed of data retrieval operations on database tables at the cost of additional storage.
Replication
The process of copying and maintaining database data across multiple servers for redundancy, failover, and read scaling.
Deadlock
A situation where two or more transactions permanently block each other by each holding locks that the other needs.
Database Index Types
Different index structures (B-tree, Hash, GIN, GiST, BRIN) optimized for various query patterns and data types.
View All Databases Terms →