T-SQL » Stored Procedures » Executing a Stored Procedure

Syntax:
[ EXEC [ UTE ] ]
    { procedure_name [ ;number ] | @procedure_name_variable }
       [ [ @parameter= ] { value | @variable [ OUTPUT ] | [ DEFAULT ] ,... } ]
[ WITH RECOMPILE ]
procedure_name
Is the name of the stored procedure.
number
An optional integer used to group procedures of the same name so they can be dropped using a single DROP PROCEDURE statement.
@procedure_name_variable
The locally defined variable that represents a stored procedure name.
@parameter
Is the parameter for a procedure, as defined in the CREATE PROCEDURE statement.
value
Is the value of the parameter to the procedure. If parameter names are not specified, parameter values must be supplied in the order defined in the CREATE PROCEDURE statement.
@variable
Is the variable that stores a parameter or a return parameter.
OUTPUT
Specifies that the stored procedure returns a parameter.
DEFAULT
Supplies the default value of the parameter as defined in the procedure.

Stored procedures can be run by using the EXEC or EXECUTE command. Parameter values can be supplied if a stored procedure is written to accept them.

Examples

Code:
EXEC spDisplayAll;
Output:
IdNameStd_CoursePhoneStd_Grade
1Job Mathew2123452
2Rock Feller4465653
3Harri Robins3787881
4Joe Philip3464562
5Nadia Alex0785654





(5 row(s) affected)
Explanation:

When we execute the spDisplayAll stored procedure, using the EXEC command, we get all the records in the 'Students' table.

Language(s): MS SQL Server