SQL Create Stored Procedure - Stored Procedure in SQL Server
Create Stored Procedure
- A stored procedure is a SQL code that can be saved and reused again.
- We can just call the stored procedure whenever it is needed.
- We can also pass the parameters to them so that it gets executed according to the parameter we pass.
Demo wikitechydatabase
- Below is a selection from the wikitechytable table used in the examples:
Syntax
CREATE PROCEDURE procedure_name AS BEGIN sql_statement END ;
Creating a Stored Procedure
- Syntax - using SELECT statement in Stored Procedure
CREATE PROCEDURE GetDataSP AS BEGIN SELECT * FROM wikitechytable END ;
Output
Execute the stored procedure
EXEC GetDataSP;
Output
Dropping a Stored Procedure
DROP PROCEDURE IF EXISTS GetDataSP;