SQL Flow Field Guide

CREATE FUNCTION

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

defines a scalar, inline table-valued, or multi-statement table-valued function

What changes

Input
module body (its own statements and their sources)
Output or change
module definition

Syntax at a glance

CREATE [ OR ALTER ] FUNCTION [ schema_name. ] function_name ( [ { @parameter_name [ AS ] [ type_schema_name. ] parameter_data_type [ NULL ] [ = default ] [ READONLY ] } [ , ...n ] ] ) RETURNS return_data_type [ WITH <function_option> [ , ...n ] ] [ AS ] BEGIN function_body RETURN scalar_expression END [ ; ]

Work example

A query needs a reusable scalar or table-valued expression with stable inputs and output.

Review schema binding, determinism, null handling, data access, and execution cost with boundary values.

Check your work The function returns the documented type and rows for normal, empty, and NULL inputs.

Open Microsoft Learn for full syntax, permissions, and details for your version.