Stored Procedure in SQL Server
SQL Server stored procedures are used to group one or more Transact-SQL statements into logical units. The stored procedure are stored as named objects in the SQL Server Database Server.
When you call a stored procedure for the first time, SQL Server creates an execution plan and stores it in the cache. In the subsequent executions of the stored procedure, SQL Server reuses the plan so that the stored procedure can execute very fast with reliable performance
You can also pass parameters to a stored procedure, so that the stored procedure can act based on the parameter value(s) that is passed.
Stored Procedure Syntax
CREATE PROCEDURE SelectAllCustomers @City nvarchar(30) AS SELECT * FROM Customers WHERE City = @City GO;
Execute Stored Procedure
EXEC SelectAllCustomers 'Varanasi';