SQL Stored Procedure with Example | MSSQL Stored Procedure Tutorial
Subscribe Our YouTube Channel For Latest Project Videos And Tutorials.
What is a Stored Procedure?
- An SQL prepared code that may be saved and reused repeatedly is known as a stored procedure.
- So, if you frequently develop SQL queries, save them as stored procedures and just call them to run them.
- Additionally, you can add parameters to a stored procedure so that it can take action based on the parameter value(s) that are passed.
Syntax:
CREATE PROCEDURE Procedure_Name
AS
Sql_Statement
GO;
OR
CREATE PROC Procedure_Name
AS
Sql_Statement
GO;
Execute a Stored Procedure:
EXEC Procedure_Name;
-------------------------------------------------------------------------------------------------------
EXAMPLE:
- The following SQL statement creates a stored procedure named "Test" that selects all records from the "Students" table:
CREATE PROCEDURE Test
AS
Select * from Students
GO;
EXEC Test;
0 Comments