语句被终止。完成执行语句前已用完最大递归 100
sql语句递归查询会员的推荐或安置关系时报错:语句被终止。完成执行语句前已用完最大递归……
服务器范围的默认值为 100。如果指定 0,则没有限制。每一个语句只能指定一个 MAXRECURSION 值使用类似的语句:
例如:
1 USE AdventureWorks2008R2; 2 GO 3 --Creates an infinite loop 4 WITH cte (EmployeeID, ManagerID, Title) as 5 ( 6 SELECT EmployeeID, ManagerID, Title 7 FROM dbo.MyEmployees 8 WHERE ManagerID IS NOT NULL 9 UNION ALL 10 SELECT cte.EmployeeID, cte.ManagerID, cte.Title 11 FROM cte 12 JOIN dbo.MyEmployees AS e 13 ON cte.ManagerID = e.EmployeeID 14 ) 15 --Uses MAXRECURSION to limit the recursive levels to 2 16 SELECT EmployeeID, ManagerID, Title 17 FROM cte 18 OPTION (MAXRECURSION 2); 19 GO