2

Why would someone use stored-procedures in .net? Also, if there is a good reason to use them, how can I?

1
  • 2
    I is kind of a "To be or not to be". It depends what you want ro achieve. More details please. Commented Jul 15, 2010 at 7:42

1 Answer 1

3

The benefits of using stored procedures in SQL Server rather than Transact-SQL programs stored locally on client computers are:

They allow modular programming.

You can create the procedure once, store it in the database, and call it any number of times in your program. Stored procedures can be created by a person who specializes in database programming, and they can be modified independently of the program source code.

They allow faster execution.

If the operation requires a large amount of Transact-SQL code or is performed repetitively, stored procedures can be faster than batches of Transact-SQL code. They are parsed and optimized when they are first executed, and a compiled version of the stored procedure remains in memory cache for later use. This means the stored procedure does not need to be reparsed and reoptimized with each use resulting in much faster execution times.

They can reduce network traffic.

An operation requiring hundreds of lines of Transact-SQL code can be performed through a single statement that executes the code in a procedure, rather than by sending hundreds of lines of code over the network.

They can be used as a security mechanism. Users can be granted permission to execute a stored procedure even if they do not have permission to execute the procedure's statements directly.

Source: http://msdn.microsoft.com/en-us/library/aa214299%28SQL.80%29.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

Stored procedures are not faster than adhoc queries. They are reparsed just like adhoc queries. Also, adhoc queries also benefit from cached query plans. Source: scarydba.com/2009/09/30/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.