Skip to main content

Why do we need triggers?

Triggers exist to automatically run actions when data in a table changes.

The main goals

  1. Maintaining data integrity. For example, automatically deleting related records when a user is deleted.
  2. Logging changes. Recording who updated or deleted data and when.
  3. Enforcing rules. You can block unwanted changes if they'd violate business logic.
  4. Automatic computations. For example, updating running totals or statistics when new data is inserted.

In short, triggers are the database's reactions to events, helping automate work and protect data from user error.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.