在存储过程结束时显式删除本地临时表有什么好处?

Any benefit to explicitly dropping local temporary tables at the end of a stored procedure?(在存储过程结束时显式删除本地临时表有什么好处?)
本文介绍了在存储过程结束时显式删除本地临时表有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

考虑以下伪 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.

这篇关于在存储过程结束时显式删除本地临时表有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert varchar to float IF ISNUMERIC(将 varchar 转换为 float IF ISNUMERIC)
multi part identifier could not be bound sql(无法绑定多部分标识符 sql)
Check if a column contains text using SQL(使用 SQL 检查列是否包含文本)
Select value if condition in SQL Server(SQL Server 中的条件选择值)
Control flow in T-SQL SP using IF..ELSE IF - are there other ways?(使用 IF..ELSE IF 在 T-SQL SP 中控制流 - 还有其他方法吗?)
Inserting a multiple records in a table with while loop (使用while循环在表中插入多条记录)