SQL Server Triggers — INSTEAD OF vs AFTER What is the SQL Server program unit that fires instead of executing the original DML statement, effectively replacing it?

Database SQL Server 2000 Difficulty: Easy
Choose an option
  • A
    INSTEAD OF trigger.
  • B
    BEFORE trigger.
  • C
    AFTER trigger.
  • D
    BEGIN trigger.
  • E
    SCHEDULED trigger.

Answer

Correct Answer: INSTEAD OF trigger.

Explanation

Introduction:SQL Server supports two trigger timings for DML: INSTEAD OF and AFTER. Knowing their semantics is crucial when enforcing complex business rules or redirecting writes to views.

Given Data / Assumptions:

  • Target: SQL Server 2000 semantics (still valid).
  • Original DML can be INSERT, UPDATE, or DELETE.

Concept / Approach:An INSTEAD OF trigger intercepts a DML statement and executes in its place. The original action does not occur unless the trigger code issues it explicitly. By contrast, an AFTER trigger fires only after the DML succeeds and is used for auditing, cascading logic, or post-conditions.

Step-by-Step Solution:1) Identify trigger type that replaces the original statement.2) Recognize that SQL Server has no BEFORE trigger timing.3) Choose INSTEAD OF as the mechanism that runs in lieu of the DML statement.

Verification / Alternative check:Create a view with an INSTEAD OF INSERT trigger; observe that inserts are handled by trigger logic and the base insert does not occur automatically.

Why Other Options Are Wrong:

  • BEFORE trigger: Not supported in SQL Server DML timing semantics.
  • AFTER trigger: Runs after the statement completes; it does not replace it.
  • BEGIN trigger / SCHEDULED trigger: Not valid SQL Server trigger types.

Common Pitfalls:Expecting Oracle-style BEFORE triggers in SQL Server, or assuming AFTER can cancel the base operation.

Final Answer:INSTEAD OF trigger.

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