开发者

Is it better to delete or declare new temp tables for SQL Stored Procedures?

开发者 https://www.devze.com 2023-01-13 20:42 出处:网络
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 s开发者_StackOverflowame time.

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 s开发者_StackOverflowame 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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消