Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Week 9 Quiz 3 Stored Procedures UDF

Total questions: 15

Worksheet time: 9mins

Name
Class
Date
1.

What is the term for a pre-compiled set of one or more SQL statements stored in a database server that can be executed as a single unit?

(a)  

2.

What is a key benefit of using stored procedures, as discussed in the presentation?

a)

They can be used directly in a WHERE clause.

b)

They are always faster than a series of individual SQL statements.

c)

They enhance security by allowing users to access data without direct table permissions.

d)

They can only return a single value.

3.

What is the primary difference between a stored procedure and a user-defined function in terms of their return value?

a)

Stored procedures can only return an integer, while functions can return any data type.

b)

Stored procedures can only return one value, while functions can return multiple values.

c)

A stored procedure may or may not return a value, while a user-defined function must return a value.

d)

There is no difference in their return values.

4.

Which SQL command is used to execute a stored procedure?

(a)  

5.

What type of User-Defined Function (UDF) is designed to return a single value, such as a string, integer, or date?

a)

Inline Table-Valued Function

b)

Multi-Statement Table-Valued Function

c)

Scalar Function

d)

Aggregate Function

6.

Which of the following is a capability of a stored procedure but is generally not a capability of a User-Defined Function?

a)

Reading from a database table.

b)

Returning multiple result sets.

c)

Accepting input parameters.

d)

Using a SELECT statement.

7.

What is a key difference in how Stored Procedures and User-Defined Functions handle their use in SQL statements?

a)

Stored procedures can be used directly in a SELECT statement, while UDFs cannot.

b)

Stored procedures are executed with EXEC, while UDFs are called by their name within a SELECT statement's FROM or WHERE clause.

c)

UDFs can modify the database with INSERT, UPDATE, or DELETE, while stored procedures cannot.

d)

Stored procedures must be executed in a separate SQL statement, while a UDF can be used within a SELECT statement's FROM or WHERE clause.

8.

What is the purpose of the DELIMITER command when creating a stored procedure or UDF in some SQL environments?

a)

It defines the character set for the procedure.

b)

It changes the statement terminator from a semicolon to a different character.

c)

It specifies the database schema for the procedure to a different character.

d)

It sets the access permissions for the procedure.

9.

When should you consider using a stored procedure instead of a function?

a)

When you need to perform data manipulation like INSERT or UPDATE.

b)

When you need a result to be used in a WHERE and FIND clause.

c)

When you need to return a single, atomic value.

d)

When you are performing a complex calculation that doesn't involve data manipulation.

10.

What is a key advantage of using parameters with stored procedures?

a)

It makes the procedure non-reusable.

b)

It prevents the procedure from executing, but more flexible and reusable.

c)

It allows for dynamic input, more flexible and reusable.

d)

It restricts the procedure to a single, static value.

11.

Scenario: You are developing a database application where you need to create a reusable component that performs several INSERT and UPDATE operations on different tables as a single transaction. You also need to control access to this operation so that users can execute it without having direct table modification permissions. Question: Based on this scenario, which is the most appropriate database object to create?

a)

A User-Defined Function, because it can perform complex logic.

b)

A View, because it simplifies data retrieval.

c)

A Stored Procedure, because it supports DML statements and offers a security layer.

d)

A Scalar Function, because it returns a single value after a calculation.

12.

Scenario: A developer writes a SQL query that uses a subquery to calculate a value and filter a result set. They find that this subquery is used in multiple different reports and queries. To improve maintainability and performance, they want to replace the subquery with a more efficient object. Question: What is the best choice to replace this recurring subquery and why?

a)

A VIEW because it can encapsulate the subquery logic.

b)

A SCALAR FUNCTION because it can encapsulate the subquery logic and return a single value for use in a WHERE clause.

c)

A STORED PROCEDURE because it is pre-compiled and offers better performance.

d)

An INLINE TABLE-VALUED FUNCTION because it can be used in the FROM clause and is often more efficient than a subquery.

13.

Scenario: A database contains a Customers table. You need to create a routine that takes a CustomerID as input and returns a count of all orders placed by that customer. This routine will be used within a SELECT statement to show each customer's order count in a report. Question: What is the most appropriate database object to create for this task?

a)

A Stored Procedure, as it can accept input.

b)

A Scalar User-Defined Function, as it can be used in a SELECT statement and returns a single value.

c)

A Table-Valued User-Defined Function, as it can return multiple rows.

d)

A simple SQL query without a function or procedure.

14.

Scenario: A stored procedure is created to update an employee's salary and takes two parameters: @EmployeeID and @NewSalary. A developer calls the procedure using EXEC UpdateEmployeeSalary 101, 75000. Question: Which of the following is the most likely purpose of this stored procedure call?

a)

To return a list of employees with salaries less than 75000.

b)

To calculate the total salary of employee ID 101.

c)

To update the salary of employee with ID 101 to 75000.

d)

To insert a new employee record with a salary of 75000.

15.

Scenario: A UDF is created to calculate an employee's annual bonus based on their performance score. The function is called within a SELECT statement on the Employees table: SELECT EmployeeName, dbo.CalculateBonus(PerformanceScore) AS Bonus FROM Employees;. Question: Why is this a valid use case for a UDF instead of a stored procedure?

a)

Stored procedures cannot be used in a SELECT statement, whereas UDFs can.

b)

UDFs are faster than stored procedures for calculations.

c)

Stored procedures cannot accept parameters like PerformanceScore.

d)

UDFs can perform DML operations, which are needed for this calculation.