Stored Procedures Quiz - Languages SQL
Free practice quiz: Stored Procedures (Languages SQL). 49 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
Play all 49 questions freeSample questions
Which keyword is used to define a stored procedure in SQL?
- CREATE PROCEDURE
- DEFINE PROCEDURE
- MAKE PROCEDURE
- INSERT PROCEDURE
Show answer
Answer: A. CREATE PROCEDURE
The `CREATE PROCEDURE` statement is the standard SQL syntax for defining a stored procedure.
What is the difference between a stored procedure and a function in SQL?
- Functions can only return single scalar values, procedures can return multiple values or result sets
- Procedures cannot accept parameters, functions can
- Functions are compiled, procedures are not
- Procedures are always faster than functions
Show answer
Answer: A. Functions can only return single scalar values, procedures can return multiple values or result sets
While there are nuances across different SQL dialects, a common distinction is that SQL functions are designed to return a single scalar value (or a table in some dialects), whereas stored procedures can return multiple result sets, output parameters, and have more control flow.
What does it mean for a stored procedure to be 'idempotent'?
- It can only be executed once
- Executing it multiple times with the same input produces the same result and state change
- It always returns a different result
- It requires specific hardware to run
Show answer
Answer: B. Executing it multiple times with the same input produces the same result and state change
An idempotent operation is one that can be applied multiple times without changing the result beyond the initial application. This is a desirable property for procedures that modify data.
What is a 'cursor' in the context of stored procedures?
- A statement that returns a result set
- A mechanism to iterate through rows of a result set one by one
- A type of stored procedure parameter
- A temporary storage area for data
Show answer
Answer: B. A mechanism to iterate through rows of a result set one by one
Cursors allow for row-by-row processing of data returned by a query within a stored procedure, though they are generally less efficient than set-based operations.
What is a common stored procedure used for managing permissions or executing administrative tasks?
- `SELECT * FROM SomeTable`
- `EXEC sp_configure` (SQL Server)
- `INSERT INTO LogTable`
- `CREATE TABLE TemporaryData`
Show answer
Answer: B. `EXEC sp_configure` (SQL Server)
System stored procedures, like `sp_configure` in SQL Server, are often used for administrative and configuration tasks. Note that system procedure names and availability vary by RDBMS.