CREATE PROC < Procedure Name>
AS
BEGIN
< T-SQL Commands>
END
Here is a simple stored procedure to retrieve data from STUDENT table:
CREATE PROC STUDENT_DATA
AS
BEGIN
SELECT * FROM STUDENT
END
Uses of creating stored procedure in this scenario is:
- Instead of running the entire set of T-SQL Commands which are inside the stored procedure, we can just run the stored procedure using the following syntax to get the same result.
Result obtained by running the T-SQL Commands inside the stored procedure:
Same result should be obtained even by running the stored procedure.
Here is the syntax to Execute a stored procedure:
Syntax:
EXEC <Procedure Name>
Result obtained by running Stored procedure is :