SQL administration task: Which SQL command is used to recompile or revalidate an existing stored function after dependencies change?

Difficulty: Easy

Correct Answer: ALTER FUNCTION

Explanation:


Introduction / Context:
When underlying tables or dependent objects change, stored program units (such as functions) may need recompilation so the database engine can validate references and refresh metadata. Knowing the correct SQL command avoids runtime errors and invalid status for schema objects.


Given Data / Assumptions:

  • An existing stored function must be recompiled or revalidated.
  • We are using vendor-neutral SQL naming where possible.
  • We want a structural command rather than session settings.


Concept / Approach:
SQL uses the ALTER verb to modify existing objects. For functions, the standard pattern is ALTER FUNCTION. Some platforms support syntax such as “ALTER FUNCTION f() COMPILE” or require re-issuing the definition through ALTER. Phrases like “SET FUNCTION” or “SET STORED FUNCTION” are not standard SQL DDL commands for recompilation.


Step-by-Step Solution:
Identify the object class: FUNCTION.Select the DDL verb for modifying existing objects: ALTER.Combine into the correct statement: ALTER FUNCTION.


Verification / Alternative check:
DBMS documentation for Oracle, PostgreSQL, SQL Server, and others shows ALTER FUNCTION as the vehicle for compiling, changing attributes, or redefining function bodies (syntax details vary, but the verb remains ALTER).


Why Other Options Are Wrong:

  • SET FUNCTION / SET STORED FUNCTION: Not standard DDL for recompilation; typically “SET” changes session options.
  • All of the above: Incorrect because only ALTER FUNCTION is correct.
  • None of the above: Incorrect given ALTER FUNCTION exists.


Common Pitfalls:
Dropping and recreating the function unnecessarily (losing privileges or dependencies) instead of using ALTER; forgetting to handle dependent objects that may also need recompilation.


Final Answer:
ALTER FUNCTION

More Questions from Database Systems

Discussion & Comments

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