在存储过程结束时显式删除本地临时表有什么好处?
考虑以下伪 T-SQL 代码(由存储过程执行):
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
语句是存储过程执行的最后一条语句——该语句有什么好处吗?
The DROP TABLE
statement is the last statement executed by the stored proceudre – is there any benefit to that statement?
请注意,我不是在询问在存储过程的中间(即在不再需要表之后,但在存储过程结束之前)删除临时表(本地或非本地)过程代码)——由于减少了继续执行存储过程所需的内存,这似乎具有重要的好处.我想知道在存储过程完成执行时显式删除表与让"SQL Server 这样做是否有任何好处(或任何影响,实际上是积极的或消极的).
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.
推荐答案
这样做不会有什么坏处,但是当连接断开时表会被删除.我个人认为进入是一个好习惯.它还可以让开发人员(可能需要为此工作),您不会忘记这样做.
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.
相关文章