In SQL Server's trigger architecture, which trigger types are supported by the engine and available for tables and views as appropriate?

Difficulty: Easy

Correct Answer: INSTEAD OF and AFTER only

Explanation:


Introduction / Context:
Triggers in SQL Server fire in response to data modification events. Knowing which trigger types are supported helps in enforcing complex constraints and audit logic.



Given Data / Assumptions:

  • Platform: SQL Server.
  • Events: INSERT, UPDATE, DELETE.
  • Objects: tables and, for INSTEAD OF, also views.


Concept / Approach:

SQL Server supports AFTER triggers (fire after the DML statement succeeds) and INSTEAD OF triggers (replace the DML operation; useful on views). It does not support BEFORE triggers like some other RDBMS engines.



Step-by-Step Solution:

1) Verify AFTER triggers exist and are common for auditing/validation.2) Verify INSTEAD OF triggers exist and are often used on views to map writes to base tables.3) Confirm no BEFORE trigger type in SQL Server.4) Conclude that supported types are INSTEAD OF and AFTER.


Verification / Alternative check:

Attempt to create a BEFORE trigger yields an error; documentation shows only AFTER and INSTEAD OF.



Why Other Options Are Wrong:

INSTEAD OF only / AFTER only: incomplete. BEFORE only: unsupported.



Common Pitfalls:

Porting code from engines that support BEFORE triggers without redesign. Overusing triggers where constraints or procedures would be clearer.



Final Answer:

INSTEAD OF and AFTER only

More Questions from SQL Server 2000

Discussion & Comments

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