« September 2009 | Main

February 18, 2010

Stored Procedures using Input Parameters

 -      Tauseef.M
 


Well guys, in my previous articles I have given a preliminary description about the Stored Procedure and also had given a word that I will be dealing with it in more detail in my upcoming articles. As the saying goes “Once a word has been allowed to escape, it cannot be recalled”, and so I am back here with advanced stored procedure concepts.


Insertion using Stored Procedure’s Input Parameters
 

Let’s get on by creating a table name tblEmployee with the following fields as below:
 

 Stored Procedures

                                    Fig (a)

Now let’s create a Stored Procedure for insertion. Open a new Query window and type the below stored procedure.

 Stored Procedures


Stored procedure named usp_insert gets created into database.
 

Execute Stored Procedure??
Yeah!! The below syntax is used for executing the above created stored procedure. 

Stored Procedures

Here EmpId Column inside the table is a primary key with identity being set to [1].


Updating table - Stored Procedure using Input Parameters


Let’s have a glance over the fig (a) above. Now we are going to use the same table for creating the stored procedure for updating the table.


Portray the same as below in a new Query Window.

Stored Procedures

Stored procedure named usp_Update gets created into database.

Execute Stored Procedure??
Before executing let us see the records inside the table tblEmployee.


Stored Procedures

Stored Procedures 

 Stored Procedures

 Stored Procedures

Deleting Records - Stored Procedure using Input Parameters

The last step in any CRUD operation is deleting the records in the table.
Let’s create a stored procedure named usp_Delete

 Stored Procedures

Execute Stored Procedure??
 

Stored Procedures

Stored Procedure using Output variables will be explained in my upcoming articles!!


(The author, Tauseef.M, is a Software Engineer at Binary Spectrum).