What is a stored procedure? Evaluate the statement: "A stored procedure is a program that performs some common action on database data and is stored in the database."
-
ACorrect
-
BIncorrect
-
CTrue only for SELECT logic
-
DTrue only in Oracle
-
EValid only for compiled procedures, not interpreted
Answer
Correct Answer: Correct
Explanation
Introduction / Context: Stored procedures encapsulate database logic on the server side. They are central to many architectures for performance, security, and maintainability, enabling clients to call a stable, parameterized routine rather than issuing ad hoc SQL directly.
Given Data / Assumptions:
- The definition concerns server-resident program units.
- We consider major DBMSs (SQL Server T-SQL procedures, Oracle PL/SQL procedures, PostgreSQL functions/procedures).
Concept / Approach: A stored procedure is a named program stored in the database catalog that can execute SQL (DML/DDL) and procedural constructs (variables, loops, conditions, exceptions). Procedures can enforce business rules, reduce network round trips, and centralize permissions—clients may get EXECUTE rights without direct table access.
Step-by-Step Solution:
Create: CREATE PROCEDURE usp_close_order @id INT AS BEGIN ... END;Store: The definition/compiled plan is persisted in the database metadata.Execute: Applications call EXEC usp_close_order @id = 42;Effect: Procedure performs actions on data in a controlled, reusable way.Verification / Alternative check: Inspect metadata views (e.g., sys.procedures in SQL Server, USER_OBJECTS in Oracle) to see stored definitions; observe permissions and execution plans managed by the DBMS.
Why Other Options Are Wrong:
- Incorrect: Contradicts standard DBMS definitions.
- Only SELECT: Procedures handle INSERT/UPDATE/DELETE and more.
- Only in Oracle: All major engines support stored program units.
- Compiled vs. interpreted: Implementation varies; the concept still matches the statement.
Common Pitfalls: Confusing stored procedures with functions (which usually return a value and may have side-effect restrictions); assuming procedures are inherently faster—benefits often come from reduced network chatter and plan reuse, not magic speed.
Final Answer: Correct