Friday, February 24, 2023

SQL Server - SQL Stored Procedure

 

Stored Procedure




Stored Procedure

A stored procedure is a prepared code that you can use again and again. Save the query as a stored procedure and then call it to execute it. The stored procedure can act based on the parameters passed to it.

 

Syntax:

CREATE PROCEDURE procedure_name
AS
sql_statement
GO;

Execute a Stored Procedure

EXEC procedure_name;

 

Example :

CREATE PROCEDURE P_Employee
AS
SELECT EmpId, Name,
FROM Employee

GO;

Stored Procedure with Parameter

CREATE PROCEDURE P_Employees @City nvarchar(30)
AS
SELECT * FROM Employees WHERE City = @City
GO;

EXEC P_Employees @City = 'Mumbai';

No comments:

Post a Comment

SQL Server - Introduction to SQL

  Introduction to SQL   SQL is a standard language for accessing and manipulating databases. SQL stands for Structured Query Language. SQL...