SQL Flow Field Guide

QUERY HINT MAXRECURSION <integer_value>

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

Specifies the maximum number of recursions allowed for this query.

What changes

Input
none
Output or change
none

Syntax at a glance

OPTION ( MAXRECURSION <integer_value> )

Work example

A recursive query needs a finite guard while its termination rule is being checked.

Use a small explicit limit in a bounded test. Prove the recursive member stops before increasing the limit.

Check your work QUERY HINT MAXRECURSION <integer_value>. The recursion returns the expected levels and stops below the selected limit.

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