在SQLServer中執行遞歸的時候出現錯誤
#子查父遞歸
With Tree As( SELECT id, parent_id FROM dbo.data_catalog C UNION ALL SELECT P.id, P.parent_id FROM dbo.data_catalog P, Tree WHERE Tree.parent_id = P.id ) SELECT * FROM data_catalog where id in (select id from Tree )
uncategorized SQLException; SQL state [S0001]; error code [530]; 語句被終止。完成執行語句前已用完最大遞歸 100。
原來SQLServer默認有個遞歸次數,如果SQL中的遞歸次數大於該閾值,就會觸發該錯誤,該值默認為100,可以手動修改該值。
修改為0 則不限制次數
With Tree As( SELECT id, parent_id FROM dbo.data_catalog C UNION ALL SELECT P.id, P.parent_id FROM dbo.data_catalog P, Tree WHERE Tree.parent_id = P.id ) SELECT * FROM data_catalog where id in (select id from Tree ) OPTION (MAXRECURSION 0)