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:



Read More


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 (


Verify your Comment

Previewing your Comment

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

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.


Post a comment on Place data definition statements at top of stored procedure – DDL | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer