How to Optimize Stored Procedure in SQL Server ?

There are many tips and tricks for the same.

  • Include SET NOCOUNT ON statement.
  • Use the schema name with the object name.
  • Do not use the prefix "sp_" in the stored procedure name.
  • Use IF EXISTS (SELECT 1) instead of (SELECT *).
  • Use the sp_executesql stored procedure instead of the EXECUTE statement for Dynamic SQLs.
  • Try to avoid using SQL Server cursors whenever possible.
  • Keep the Transaction as short as possible.
  • Use TRY-Catch for error handling.
  • Optimize queries and fine-tune indexes.
  • Use table variables and temp tables appropriately.


You May Interest

What is the Difference Between Update Lock and Exclusive Lock in ...

What is Log Shipping in SQL Server ?

What is an Online Rebuilding of Indexes in SQL Server ?

Getting the Id of MS SQL Server Last Entered Record

MS SQL Compiling a Stored Procedure With a Requery