In this article, I will show you how to use a Stored Procedure in SQL.
The SQL query we saved as a stored procedure, we can also pass the parameter(s) to a stored procedure so we can execute the stored procedure with parameter.
A) Create Command Syntax
CREATE PROCEDURE procedure_name
AS
sql_statement
GO;
example:
CREATE PROCEDURE GetCurrency
AS
Select * from Sales.Customer
B) Alter command Syntax
If you want to modify existing Stored procedure you need to Alter like below syntax
ALTER PROCEDURE procedure_name
As
sql_statement
GO;
example:
ALTER PROCEDURE GetCurrency
AS
Select * from Sales.Customer=1
C) Drop command Syntax
if you want to drop stored procedure you need to follow following syntax
DROP PROCEDURE procedure_name
example:
Drop procedure GetCurrency
D)To execute stored without parameter syntax
Exec procedure_name
example:
Exec GetCurrency
E)To execute stored procedure with parameter syntax
Exec procedure_name parameter(s)=value(s)
Example:
Exec GetCurrency @currencyName='Doller'