[英]drop temp table not take effect for SQL Server
I had a query script in SQL server management studio which is as below: 我在SQL server management studio中有一个查询脚本,如下所示:
if OBJECT_ID('tempdb..#temp') IS NOT NULL
drop table #temp
select somecolumn into #temp from sometable where somecondition
if OBJECT_ID('tempdb..#temp') IS NOT NULL
drop table #temp
select somecolumn2 into #temp from sometable2 where somecondition2
I add the drop table line to ensure the #temp table is cleaned from the cache. 我添加了drop table行以确保从缓存中清除#temp表。 However, for repeated running the script, I still got error as "here is already an object named '#temp' in the database."
但是,为了重复运行脚本,我仍然会收到错误,因为“这里已经是数据库中名为'#temp'的对象了。” in the second select line.
在第二个选择行中。 It seems that the drop table didn't take effect as I wish.
似乎丢弃表没有按照我的意愿生效。
if OBJECT_ID('tempdb..#temp') IS NOT NULL
drop table #temp
select somecolumn into #temp from sometable where somecondition
GO --<-- Separate these two block with a batch separator
if OBJECT_ID('tempdb..#temp') IS NOT NULL
drop table #temp
select somecolumn2 into #temp from sometable2 where somecondition2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.