Creating Stored Procedures

You create stored procedures using the CREATE PROCEDURE statement. Permission to execute CREATE PROCEDURE defaults to the database owner, who can transfer it to other users. Stored procedures are database objects, and their names must follow the rules for identifiers. You can create a stored procedure only in the current database.

With the exception of CREATE statements, any number and type of SQL statements can be included in stored procedures. (For more information about the rules for creating stored procedures, see Stored Procedure Rules.)

You can nest stored procedures (have one stored procedure call another) up to 16 levels. The nesting level increases by one when the called procedure begins execution and decreases by one when the called procedure completes execution. Attempting to exceed the maximum of 16 levels of nesting causes the whole calling procedure chain to fail. The current nesting level is stored in the @@NESTLEVEL global variable.

After procedures are created, they are executed.

    To create a stored procedure

Or