In sqlserver, I tried to define a stored procedure to recursively invoke itself (see the following T-SQL statements ). however, the maximum nesting level of recursion is 30 (tested under SQL Server 2000 ). once the nesting level is exceeded, an error will occur. another thing I 'd like to mention here is that, there wocould be a warning message prompted by SQL Server as 'could not Add rows to sysdepends for the current stored procedure because it depends on the missing object 'test _ recursion '. the stored procedure will still be created. '.
Create procedure test_recursion
@ Count Int = 10
As
Declare @ CNT int;
Set @ CNT = @ count-1;
Print 'executing stored procedre: '+ Cast (@ count as nvarchar );
If @ CNT> 0 execute test_recursion @ CNT; -- Recursive Invocation.
Go
Execute test_recursion 30; -- the maximum nesting level of stored procedure is 30.
The output result of this procedure is as follows:
Cannot Add rows to sysdepends for the current stored procedure because it depends on the missing object 'test _ recursion'. The stored procedure will be still be created.
Executing stored procedre: 30
Executing stored procedre: 29
Executing stored procedre: 28
Executing stored procedre: 27
Executing stored procedre: 26
Executing stored procedre: 25
Executing stored procedre: 24
Executing stored procedre: 23
Executing stored procedre: 22
Executing stored procedre: 21
Executing stored procedre: 20
Executing stored procedre: 19
Executing stored procedre: 18
Executing stored procedre: 17
Executing stored procedre: 16
Executing stored procedre: 15
Executing stored procedre: 14
Executing stored procedre: 13
Executing stored procedre: 12
Executing stored procedre: 11
Executing stored procedre: 10
Executing stored procedre: 9
Executing stored procedre: 8
Executing stored procedre: 7
Executing stored procedre: 6
Executing stored procedre: 5
Executing stored procedre: 4
Executing stored procedre: 3
Executing stored procedre: 2
Executing stored procedre: 1