Where SQL can appear:\nJudge the statement:\n\n"SQL statements can be embedded in triggers, stored procedures, and program code."

Difficulty: Easy

Correct Answer: Correct

Explanation:


Introduction / Context:
SQL is used in multiple contexts: inside database-resident program units (procedures, functions, triggers) and in external application code via APIs such as JDBC, ODBC, ADO.NET, or embedded SQL preprocessors. This question verifies that you recognize these locations as valid places for SQL.


Given Data / Assumptions:

  • Typical enterprise DBMS capabilities are assumed (procedural languages and trigger support).
  • Applications use drivers or ORMs to send SQL to the DBMS.


Concept / Approach:
Triggers and stored procedures are server-side constructs that execute in the DBMS process and can contain DML (SELECT/INSERT/UPDATE/DELETE) and often DDL (with permissions). Application code can issue SQL through parameterized commands, prepared statements, or ORM-generated SQL.


Step-by-Step Solution:

In triggers: respond to INSERT/UPDATE/DELETE/DDL events and run SQL to enforce rules/logging.In stored procedures: encapsulate business logic and data access; expose stable interfaces.In programs: use drivers to send SQL, fetch results, and commit/rollback transactions.


Verification / Alternative check:
Review vendor docs: PL/SQL (Oracle), T-SQL (SQL Server), PL/pgSQL (PostgreSQL) all allow embedded SQL; Java/Python/C# samples show SQL execution from code.


Why Other Options Are Wrong:

  • Incorrect: Conflicts with standard practice.
  • Only SELECT: DML and even some DDL are common in these contexts.
  • Only in ANSI/ISO DBMSs: This capability is widespread beyond strict standard scope.
  • Dynamic but not static SQL: Both forms exist depending on language/tooling.


Common Pitfalls:
Believing that SQL belongs solely in applications and not in the database; overlooking governance benefits of procedures/triggers (centralized logic, permissions).


Final Answer:
Correct

More Questions from SQL for Database Construction

Discussion & Comments

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