为什么临时表在完成其范围后不删除?
我们在存储过程中创建了临时表,并且在运行存储过程时,临时表在 TempDB 中创建。
在我的 SP 中,我编写了代码以在手动完成所有操作后删除该临时表。
但它仍然存在于 TempDB 中并且没有被删除。但是当我重新启动 SQL 连接时,该表已被删除。我不明白这种情况如何在我的数据库中发生。
为什么我的临时表在其范围完成后没有被删除?
谁能帮我解决这个问题吗?
Possible Duplicate:
Why are temporary tables not removed from tempdb in SQL Server?
We have created Temporary tables in a stored procedure and while running the stored procedure the Temparory table is created in the TempDB.
In my SP I have written code to drop that temporary table after completion of all operations manually.
But it is still there in the TempDB and not dropped. But when I restarted the SQL connection then the table had been dropped. I don't understand how this type of scenario happen in my DB.
Why are my temporary tables not dropped after completion of their scope?
Can anyone help me out this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定为什么你的表没有被删除,但是你可以使用表变量(@TableName)而不是临时表(#TableName)吗?那么你就根本不用担心它会被丢弃,而且一旦超出范围它就会被删除......
I'm not sure why your table is not being dropped, but could you get away with using a table variable (@TableName) instead of a temp table (#TableName)? Then you wouldn't have to worry about dropping it at all, and it would be removed as soon as it goes out of scope...