stored procedure syntax code example

Example 1: sql server stored procedure

CREATE PROCEDURE spGetEmployeeCountByGender
@Gender nvarchar(20),
@EmployeeCount int Output
AS
BEGIN
SELECT @EmployeeCount = COUNT(Id) 
FROM tblEmployee 
WHERE Gender = @Gender
END

Example 2: create select stored procedure in sql server

CREATE PROCEDURE sp_getRaces
AS
BEGIN 
SELECT * FROM dbo.Races
END ;

Example 3: procedure in sql

-Stored procedure is a group of SQL
statements that has been created 
and stored in the database.
-A stored procedure will accept input 
parameters so that a single procedure
can be used over the network by several
clients using different input data.
-A stored procedures will reduce
network traffic and increase the performance. 
If we modify a stored procedure all the
clients will get the updated stored procedure.

Sample of creating a stored procedure
CREATE PROCEDURE test_display AS
SELECT FirstName, LastName FROM tb_test
EXEC test_display

Tags:

Sql Example