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:
stored-procedure-table

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

create-stored-procedure

Execute the stored procedure

EXEC GetDataSP;

Output

call-stored-procedure

Dropping a Stored Procedure

DROP PROCEDURE IF EXISTS GetDataSP;

Output

drop-stored-procedure


Related Searches to SQL Create Stored Procedure - Stored Procedure in SQL Server