Recall & Review
beginner
What is a user-defined function (UDF) in SQL?
A user-defined function is a custom function created by the user to perform specific tasks or calculations that can be reused in SQL queries.
Click to reveal answer
beginner
How do you call a user-defined function in a SQL query?
You call a user-defined function by using its name followed by parentheses, optionally passing arguments inside the parentheses, like: SELECT function_name(arguments);
Click to reveal answer
intermediate
What are the two main types of user-defined functions in SQL?
The two main types are scalar functions, which return a single value, and table-valued functions, which return a table (multiple rows and columns).
Click to reveal answer
beginner
Why use user-defined functions instead of repeating code in SQL?
User-defined functions help avoid repeating code, make queries easier to read, and allow reusing logic in many places, saving time and reducing errors.
Click to reveal answer
intermediate
Can user-defined functions modify data in SQL tables?
No, user-defined functions cannot change data in tables. They only return values and do not perform insert, update, or delete operations.
Click to reveal answer
What does a scalar user-defined function return?
✗ Incorrect
Scalar functions return a single value, such as a number or text.
Which SQL statement is used to create a user-defined function?
✗ Incorrect
User-defined functions are created using the CREATE FUNCTION statement.
Can a user-defined function perform INSERT operations on tables?
✗ Incorrect
User-defined functions cannot modify data; they only return values.
What is a benefit of using user-defined functions?
✗ Incorrect
User-defined functions simplify complex calculations by encapsulating logic.
How do you pass input to a user-defined function?
✗ Incorrect
Input is passed to functions as parameters inside parentheses.
Explain what a user-defined function is and why it is useful in SQL.
Think about how you might reuse a calculation many times.
You got /4 concepts.
Describe the difference between scalar and table-valued user-defined functions.
One returns one value, the other returns many rows.
You got /4 concepts.