views:

38

answers:

2

I have a stored procedure with a few steps. Two of the steps require the use of a DECLARE TABLE but I do not require these tables at the same time.

The tables both have 2 BIGINT columns and may have up to 100 rows.

Is it better practice to declare the two tables or to DELETE and re-use one?

EDIT: If you're interested, this is a follow-up to the stored procedure devised in this question

+2  A: 

There would be only an extremely small overhead in creating the second table. However, if they have the same columns, and you don't need the data, just delete and reuse. If you have an identity column that you use for cursor free looping (last code example in this answer), you may want to just create the second one.

KM
It's cursor free, using `MERGE` statements. There is no looping, just a few steps. I suspect no noticeable difference in performance for my specific use but I was just looking for a general guideline on handling this for potentially larger tables in the future.
Matthew PK
I would probability not use a table @variable for large data, a regular #Temp table would perform better with lots of rows
KM
Where would you draw the line for using a variable versus a#Temp ?
Matthew PK
@Matthew PK: See [What's the difference between a temp table and table variable in SQL Server?](http://stackoverflow.com/questions/27894/whats-the-difference-between-a-temp-table-and-table-variable-in-sql-server) and [Temporary Tables vs. Table Variables and Their Effect on SQL Server Performance](http://www.sql-server-performance.com/articles/per/temp_tables_vs_variables_p1.aspx) for good discussions of @variable vs. #temp.
Joe Stefanelli
+1  A: 

First off, you cannot truncate a table variable. You'd have to delete from instead. For such a small number of rows, I think it would make very little difference one way or the other. Go with whichever makes your code more readable.

Joe Stefanelli