Trigger behavior: are database triggers stored programs that must be called explicitly in order to run, or do they fire automatically when their event occurs?

Difficulty: Easy

Correct Answer: Incorrect

Explanation:


Introduction / Context:
Triggers are a core database feature used to enforce rules, log changes, or maintain derived data. A common misunderstanding is that triggers are like stored procedures that you must call directly. In reality, triggers are bound to table or view events and execute automatically when those events occur.



Given Data / Assumptions:

  • Triggers are defined on data change events such as INSERT, UPDATE, or DELETE.
  • They can be row-level or statement-level depending on the DBMS and definition.
  • They reside in the database catalog and are invoked by the server engine.


Concept / Approach:
A trigger is a declarative hook: once created, it fires automatically before or after the specified DML event on the target object. Unlike procedures or functions, which are invoked via CALL or SELECT, a trigger runs because the triggering event happened, not because a user explicitly invoked it. This makes triggers suitable for auditing, enforcing complex constraints, and propagating changes.



Step-by-Step Solution:

Define a trigger on a table for INSERT.Execute an INSERT on that table.Observe that the trigger executes without an explicit CALL.Conclude that triggers do not need manual invocation; they fire automatically.


Verification / Alternative check:
Temporarily disable the trigger; perform the DML; note that its logic no longer runs—confirming that the engine, not user code, invokes it in response to events.



Why Other Options Are Wrong:

  • Correct: Would imply triggers require explicit calls; not true.
  • Only true for statement/row-level or legacy: Trigger auto-invocation applies broadly, regardless of granularity or modernity.


Common Pitfalls:
Doing business logic exclusively in triggers leading to opaque side effects; creating recursive trigger behavior.



Final Answer:
Incorrect

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion