Monday, May 5, 2008

Why Stored Procedures

The stored procedure are used in order to speed up database services
How
1)The Stored Procedures are Basically executed in the client side database engine so that Is can use all the privileges by the database Engine
2) in order to design the procedure basically we pass some command line arguments so the other hackers cant easily retrieve the data
3) The query injection (which is described in the next topic ) can be avoided
4) in Sql Server we can use ‘create procedure ‘ (arguments)
For the procedure creation
Example

CREATE PROCEDURE dbo.usp_ name
(
@Argument )
AS
SET NOCOUNT ON;
SELECT fields FROM tablename
WHERE (Keyvalue= @argument codition)
GO

Here the procedure is used to get a Data From DB by a condition

Even we can use
If condition
Else
End
In the SQL DB like the same above procedure can be used to access all value and a conditioned value
CREATE PROCEDURE dbo.usp_ name
(
@Argument )
AS
SET NOCOUNT ON;
If @Argument=null
begin
SELECT fields FROM tablename
End
Else
Begin
SELECT fields FROM tablename
WHERE (Keyvalue= @argument codition)
end
GO

Here if we passed null as argument then is will select all value else search by the Condition
Like this we can use all the sql statements in the stored procedures

No comments: