Databases & Data Storage

Trigger

Definition

A database trigger is a special stored procedure that is automatically executed in response to certain events on a particular table or view in a database. The trigger is mostly used for maintaining the integrity of the information on the database.

Why It Matters

Triggers allow for the enforcement of complex business rules at the database level. They can be used to create audit trails, prevent invalid transactions, or automatically update related data.

Contextual Example

A trigger could be set up on an `Inventory` table. Whenever an `UPDATE` is made to the `quantity` column, the trigger automatically writes a record to an `AuditLog` table with the old value, the new value, and a timestamp.

Common Misunderstandings

  • Triggers are implicit; they fire automatically and cannot be called directly.
  • Overuse of triggers can make it hard to understand what is happening in a system, as they introduce "magic" behavior that is not visible in the application code.

Related Terms

Last Updated: December 17, 2025