忘记删除临时表,现在我无法删除它
我编写了一个存储过程并创建了一个临时表#TempHitRatioTable。我忘记将 drop table 语句放入我的过程中,现在无论我做什么,我都无法摆脱临时表,也无法重新执行该过程。我尝试完全断开与服务器的连接并重新连接,但它仍然存在。我已经尝试过以下语句:
IF OBJECT_ID('tempdb..#TempHitRatioTable') IS NOT NULL
DROP TABLE #TempHitRatioTable
我也尝试过:
IF EXISTS(SELECT * FROM sys.tables WHERE name LIKE '#TempHitRatioTable%')
DROP TABLE #TempHitRatioTable
IF EXISTS(SELECT 1 FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'#TempHitRatioTable') AND type = (N'U')) DROP TABLE #TempHitRatioTable
但我仍然无法摆脱该表。我的存储过程不再运行,我尝试运行它的水晶报表也不再运行,但似乎没有任何作用。请帮忙。
I wrote a stored procedure and created a temp table #TempHitRatioTable. I forgot to put the drop table statement in my procedure and now no matter what I do I can't get rid of the temporary table and can't re-execute the procedure. I have tried completely disconnecting from the server and reconnecting, but it is still there. I have tried the following statements:
IF OBJECT_ID('tempdb..#TempHitRatioTable') IS NOT NULL
DROP TABLE #TempHitRatioTable
and I also tried:
IF EXISTS(SELECT * FROM sys.tables WHERE name LIKE '#TempHitRatioTable%')
DROP TABLE #TempHitRatioTable
IF EXISTS(SELECT 1 FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'#TempHitRatioTable') AND type = (N'U')) DROP TABLE #TempHitRatioTable
But I still can't get rid of that table. My stored procedure is no longer running, nor is the crystal report I tried to run it on, but nothing seems to work. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道发生了什么事。我已将创建表放在游标底部,因此每次游标迭代以添加新记录时,表都已创建。我将创建表移动到存储过程的顶部,在创建游标之前,添加了语句: IF OBJECT_ID('tempdb..#TempHitRatioTable') IS NOT NULL DROP TABLE #TempHitRatioTable 在过程的顶部,然后我将 drop table 语句添加到过程末尾,一切正常。我可以根据需要多次运行它,并获取所有结果,而不仅仅是一条记录。愚蠢的我:-)
I figured out what was happening. I had put the create table at the bottom of the cursor inside of it, so each time the cursor iterated throught to add a new record the table was already created. I moved the create table to the top of the stored procedure, before I created the cursor, added the statement: IF OBJECT_ID('tempdb..#TempHitRatioTable') IS NOT NULL DROP TABLE #TempHitRatioTable at the top of the procedure, then I added the drop table statement to the end of the procedure and all is well. I can run it as many times as I want and get all my results back not just one record. Silly me :-)