Stored procedures without input and output parameters

Stored procedures can be created without input parameters. Here is the syntax for the stored procedure without input parameters.

                   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 :


This entry was posted in . Bookmark the permalink.

Leave a reply