Bird
0
0

Which of the following is the correct syntax to create a scalar user-defined function in SQL Server?

easy📝 Syntax Q3 of 15
SQL - Stored Procedures and Functions
Which of the following is the correct syntax to create a scalar user-defined function in SQL Server?
ACREATE FUNCTION dbo.GetSquare RETURNS INT AS BEGIN RETURN @num * @num END
BCREATE PROCEDURE dbo.GetSquare(@num INT) RETURNS INT AS BEGIN RETURN @num * @num END
CCREATE FUNCTION dbo.GetSquare(@num INT) RETURNS INT AS BEGIN RETURN @num * @num END
DCREATE FUNCTION dbo.GetSquare(@num INT) RETURNS TABLE AS BEGIN RETURN @num * @num END
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct function syntax

    CREATE FUNCTION dbo.GetSquare(@num INT) RETURNS INT AS BEGIN RETURN @num * @num END correctly defines a scalar function with parameter, return type, and body.
  2. Step 2: Check other options for errors

    CREATE PROCEDURE dbo.GetSquare(@num INT) RETURNS INT AS BEGIN RETURN @num * @num END uses PROCEDURE instead of FUNCTION; C misses parameter; D returns TABLE but body returns scalar.
  3. Final Answer:

    CREATE FUNCTION dbo.GetSquare(@num INT) RETURNS INT AS BEGIN RETURN @num * @num END -> Option C
  4. Quick Check:

    Correct scalar function syntax = CREATE FUNCTION dbo.GetSquare(@num INT) RETURNS INT AS BEGIN RETURN @num * @num END [OK]
Quick Trick: Use CREATE FUNCTION with RETURNS and BEGIN...END [OK]
Common Mistakes:
  • Using CREATE PROCEDURE instead of FUNCTION
  • Omitting parameters in function definition
  • Mismatching return type and body

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes