Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to change the max recursion level in sql?


Asked by Rylee Santiago on Dec 10, 2021 SQL



But you can change the level by using the MAXRECURSION option/hint. The recursion level ranges from 0 and 32,767. If your CTEs recursion level crosses the limit then following error is thrown by SQL Server engine: The statement terminated. The maximum recursion 100 has been exhausted before statement completion.
In addition,
CTEs also provide an option to set a MAXRECURSION level value between 0 to 32,767. Specifying it’s value as 0 means no limit to the recursion level, you agreed for a risk in case of a poorly written query resulting in infinite recursion level.
Thereof, MAXRECURSION hint is very helpful in a scenario where poorly written CTE is resulting in an infinite recursion level, in such cases MAXRECURSION terminates the CTE once the defined recursion crosses.
Keeping this in consideration,
The number of recursions is a non-negative integer between 0 and 32,767. When 0 is specified, no limit is applied. If the MAXRECURSION query hint is not specified, the default limit is 100. When the specified or default number for MAXRECURSION limit is reached during query execution, the query is ended and an error is returned.
Just so,
The maximum recursion 100 has been exhausted before statement completion. To overcome this error message, the MAXRECURSION query hint can be specified to increase the maximum number of recursion from the default value of 100 to a maximum of 1000.