Sqlserver-dba.com

Subscribe

SQLServer-DBA.com Links

Subscribe to newsletter

Dba_db2_button

Powered by TypePad
Place data definition statements at top of stored procedure – DDL

13 March,2013 by Jack Vamvas

Place CREATE TEMP TABLE ,  DECLARE TABLE  variables and  ALTER TABLE  data definition lamguage (DDL) statements at the top of any stored procedure or function.    The causes the stored procedure to recompile in one batch.

Avoid placing these statements in multiple places , as a recompile is forced on each occasion.  Keep it to one recompilation by placing the  CREATE TEMP TABLE ,  DECLARE TABLE  , ALTER TABLE  statements at the stored procedure beginning.

Excessive recompilations are CPU cycle expensive. Therefore minimizing recompilations  will assist in maintaining SQL Server performance. Read more on recompilation troubleshooting SQL Server - How to improve Execution Plan Reuse - SQL Server DBA

Use these two event classes to trace and identify recompilation at a stored procedure and stored procedure level:

SQL:StmtRecompile

SP:Recompile

Read More

SQL Server – AUTO CREATE STATISTICS - SQL Server DBA

SQL Server – Find high impact queries with sys.dm_exec_query_stats

SQL Server execution plan as text - SQL Server DBA

SQL Server Query Optimizer and Statistics - SQL Server DBA

 


Author: Jack Vamvas (http://www.sqlserver-dba.com)

******** *******

Enjoy this post? Enter your email address for updates on new posts:

Delivered by FeedBurner

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer