Thursday, August 18, 2016

SQL Store procedure for database server

Store procedure is very useful for  record the useful query that we have to use almost everyday . Suppose we have a system that we have to check money  transaction in a large database system like industrial and banking sector there store procedure must needed ,for checking balance because you can’t always spend time for  writing same complex query . You can just save the whole code by store procedure. Further  we don’t need to worry just execute the procedure name .

Store procedure :

Create procedure use for create procedure name . Name of the procedure what you want. I give erf in this SQL Procedure query.It's a procedure about select all the data from the the table.It's a simple query. Basically every organization  need store procedure on there software for generate result without the helping of database programmer.

CREATE PROCEDURE erf
AS
select * from coolx;

For use created procedure just have to run. Anytime just execute the name of the procedure and get the result. 

Execute erf;

Another  benefit of  store procedure  pass the parameter . By passing parameter get the specific result.
Here i pass parameter @Ldata  . You can give any name  you want but the where clause column should be same as database column name you give, use that column you want to matching .

CREATE PROCEDURE erf @Ldata nvarchar(30)
AS
SELECT *
FROM coolx
WHERE Ldata = @Ldata


For use created procedure just have to run. Anytime just execute the name of the procedure and get the result. Here i pass we on the parameter .It will find the matching result values every time when you run the query.


EXEC erf @Ldata = 'we'

No comments:

Post a Comment