問題描述
考慮以下偽 T-SQL 代碼(由存儲過程執(zhí)行):
Consider the following psuedo T-SQL code (performed by a stored procedure):
CREATE TABLE #localTable ...
<do something with the temporary table here>
DROP TABLE #localTable;
DROP TABLE
語句是存儲過程執(zhí)行的最后一條語句——該語句有什么好處嗎?
The DROP TABLE
statement is the last statement executed by the stored proceudre – is there any benefit to that statement?
請注意,我不是在詢問在存儲過程的中間(即在不再需要表之后,但在存儲過程結(jié)束之前)刪除臨時表(本地或非本地)過程代碼)——由于減少了繼續(xù)執(zhí)行存儲過程所需的內(nèi)存,這似乎具有重要的好處.我想知道在存儲過程完成執(zhí)行時顯式刪除表與讓"SQL Server 這樣做是否有任何好處(或任何影響,實(shí)際上是積極的或消極的).
Note that I'm not asking about dropping temporary tables (local or not) in the middle of the stored procedure (i.e. after the tables are no longer needed, but before the end of the stored procedure code) – that could seemingly have important benefits due to decreasing the memory required to continue executing the stored procedure. I want to know whether there's any benefit (or any effect, really, positive or negative) to explicitly dropping the table versus 'letting' SQL Server do so when the stored procedure finishes executing.
推薦答案
這樣做不會有什么壞處,但是當(dāng)連接斷開時表會被刪除.我個人認(rèn)為進(jìn)入是一個好習(xí)慣.它還可以讓開發(fā)人員(可能需要為此工作),您不會忘記這樣做.
Won't hurt to do so, but the table gets dropped when the connection is dropped. I personally think it's a good habit to get into. It also lets developers, who might have to work on this, that you didn't simply forget to do it.
這篇關(guān)于在存儲過程結(jié)束時顯式刪除本地臨時表有什么好處?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!