What is a trigger?\nEvaluate the statement:\n\n"A trigger is a stored program that is attached to a database."

Difficulty: Easy

Correct Answer: Incorrect

Explanation:


Introduction / Context:
Triggers are special stored program units that execute automatically in response to specific database events. The precise attachment point matters: in most DBMSs, DML triggers are attached to a table or view, while some systems also support database- or server-level DDL/event triggers. The statement here is overly vague and misleading.


Given Data / Assumptions:

  • We consider common DBMSs (SQL Server, Oracle, PostgreSQL, MySQL).
  • The statement does not limit itself to DML vs. DDL triggers.


Concept / Approach:
The standard definition associates DML triggers with a specific table or view: they fire on INSERT, UPDATE, or DELETE to that object. Some systems also provide DDL triggers that fire on CREATE/ALTER/DROP events at the database or schema scope. Therefore, saying a trigger is “attached to a database” incorrectly suggests that is the normal attachment for all triggers, which is not the case.


Step-by-Step Solution:

Typical: CREATE TRIGGER t_ai ON table_name AFTER INSERT ... — attached to a table/view.Less common but supported: CREATE TRIGGER ddl_db_trg ON DATABASE ... — database-scope DDL events (vendor-specific).Conclusion: The generalized statement is inaccurate; the usual attachment is to a table/view, not the database.


Verification / Alternative check:
Check vendor docs: SQL Server distinguishes DML triggers (on tables/views) and DDL triggers (on DATABASE/ALL SERVER). PostgreSQL uses triggers on tables; event triggers exist for DDL at database level.


Why Other Options Are Wrong:

  • Correct: Overly broad; misses the table/view attachment requirement for DML triggers.
  • Valid only for DDL triggers: While this caveat can sometimes be true, the original statement is still misleading as a definition.
  • Vendor-specific claims: Both Oracle and PostgreSQL primarily attach DML triggers to tables/views; database-level event triggers are a separate feature.


Common Pitfalls:
Defining triggers at the wrong scope; assuming a trigger can “watch everything” in a database by default; forgetting that triggers execute with transaction semantics tied to the firing statement.


Final Answer:
Incorrect

More Questions from SQL for Database Construction

Discussion & Comments

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