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

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.

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
SQL query to group by day(按天分组的 SQL 查询)
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)