-
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:
| Id | Name | Std_Course | Phone | Std_Grade |
| 1 | Job Mathew | 2 | 12345 | 2 |
| 2 | Rock Feller | 4 | 46565 | 3 |
| 3 | Harri Robins | 3 | 78788 | 1 |
| 4 | Joe Philip | 3 | 46456 | 2 |
| 5 | Nadia Alex | 0 | 78565 | 4 |
|
|
|
|
|
(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