Nested Procedures

Procedure nesting occurs when one stored procedure calls another.

  • If you execute a procedure that calls another procedure, the called procedure can access objects created by the calling procedure.

  • The nesting level increments when the called procedure begins execution, and decrements when the called procedure completes execution. Exceeding the maximum of 16 levels of nesting causes the transaction to fail.

  • You can call another procedure by name or by a variable name in place of the actual procedure name.

  • The current nesting level is stored in the @@nestlevel global variable.

  • execute as procedures can be nested with the nested procedures being created with or without the execute as clause