STORED PROCEDURE in SQL

WHAT IS A STORED PROCEDURE IN SQL?

Stored Procedure in SQL is a group of SQL Statements stored in the database for performing a particular task.

Syntax of stored procedure in SQL-

CREATE PROCEDURE <Procedure_Name> AS

<SQL_statements>

GO;

Syntax to execute stored procedure in SQL-

EXEC Procedure_Name;

Syntax of Stored Procedure with Parameter in SQL-

CREATE PROCEDURE <Procedure_Name> @<Parameter_Name1> <datatype (size)>โ€ฆโ€ฆ.. @<Parameter_NameN> <datatype (size)> AS

<SQL_statements>

GO;

Syntax to execute Stored Procedure in SQL-

EXEC Procedure_Name

@Parameter_Name1=Value1,โ€ฆ

@Parameter_NameN=ValueN;

Example of Stored Procedure in SQL-

CREATE PROCEDURE Allcustomers @City NVARCHAR(50), @PostalCode NVARCHAR(50) AS

SELECT *

FROM Customers

WHERE City=@City AND  PostalCode = @PostalCode 

GO;

EXEC Allcustomers @City=โ€˜Londonโ€™ , @PostalCode=โ€˜WA1 1DPโ€™;


Posted

in

Tags:

Comments

Leave a Reply