In SQL and relational databases, what do we call a stored program attached to a table or view that automatically fires in response to DML events (INSERT, UPDATE, DELETE)?

Difficulty: Easy

Correct Answer: Trigger

Explanation:


Introduction / Context:
Automation in databases often relies on server-side programs that react to data changes. These programs help enforce integrity, transform data, or audit changes close to the data.



Given Data / Assumptions:

  • The mechanism is attached to a table or view.
  • It fires automatically on INSERT, UPDATE, or DELETE events.
  • It runs inside the same transaction as the triggering statement.


Concept / Approach:
A trigger is a stored routine associated with a table or view that executes in response to DML events. Triggers can be BEFORE or AFTER (depending on RDBMS), row-level or statement-level, and are used for auditing, denormalized updates, validation, and enforcing complex constraints not expressible with CHECK or foreign keys.



Step-by-Step Solution:

Identify the behavior: automatic execution on DML.Map to database feature → trigger.Confirm scope: bound to a table or a view, not free-standing.


Verification / Alternative check:
RDBMS documentation consistently defines triggers as the event-driven database programs attached to tables/views.



Why Other Options Are Wrong:
Pseudofile / Rowset macro / Auto-procedure: Not standard SQL terms.
Embedded SELECT statement: A query inside another, not an event-driven routine.



Common Pitfalls:
Overusing triggers for business logic that belongs in the application; triggers should be reserved for data-integrity concerns or unavoidable side effects.



Final Answer:
Trigger

Discussion & Comments

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