Why stored procedures

Why Consider Stored Procedures?
1. The first time the stored procedure is run, it gets compiled. This produces an execution plan—essentially a record of the steps that Microsoft® SQL Server™ must take to get the results specified by the T-SQL in the stored procedure. The execution plan is then cached in memory for future use. This improves the performance of the stored procedure in that SQL Server does not need to analyze the code again to figure out what to do with it; it can simply refer to the cached plan. This cached plan is available until SQL Server is re-started, or until it is aged out of memory due to low usage.
2. Performance : The cached execution plan used to give stored procedures a performance advantage over queries. However, for the last couple of versions of SQL Server, execution plans are cached for all T-SQL batches, regardless of whether or not they are in a stored procedure. Therefore, performance based on this feature is no longer a selling point for stored procedures.
3. Stored procedures can still provide performance benefits where they can be used to reduce network traffic. You only have to send the EXECUTE stored_proc_name statement over the wire instead of a whole T-SQL routine
4. Maintainability and Abstraction: In a perfect world, your database schema would never change and your business rules would never get modified, but in the real world these things happen
5. Also, by abstracting the implementation and keeping this code in a stored procedure, any application that needs access to the data can get it in a uniform manner. You don't have to maintain the same code in multiple places, and your users get consistent information.

References:
http://msdn.microsoft.com/en-us/library/ms973918.aspx
http://sqlserverpedia.com/wiki/Query_Processing_-_Caching_Execution_Plans

Comments

Popular posts from this blog

Understanding Top line and Bottom line?

How to activate PF UAN account

Scrum Master vs Product Owner