在sql2005加入了cte实现sql递归,大致语法如下:
WITH batchTable(batch) AS
(
select 8000 batch
UNION ALL
SELECT batch+1 from batchTable where batch+1<8180
)
select * from batchTable OPTION (MAXRECURSION 1000)
要点一:实现递归查询一定要有递归出口,否则就成了死循环了
要点二:OPTION (MAXRECURSION 1000) 规定最大的递归次数为1000