What is a trigger in a database?

Answer

A trigger is a stored procedure that automatically executes in response to specific events (INSERT, UPDATE, DELETE) on a table. Triggers can fire BEFORE or AFTER the event and have access to the old and new row values (OLD and NEW pseudo-records). Common uses: audit logging (recording who changed what and when), enforcing complex business rules, automatically updating derived columns, and maintaining materialized data. Drawbacks: triggers are invisible to application code, making debugging difficult. Many teams prefer handling audit/business logic in the application layer for better observability and testability.