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

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.

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

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

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)