繁体   English   中英

drop temp table对SQL Server不起作用

[英]drop temp table not take effect for SQL Server

我在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

我添加了drop table行以确保从缓存中清除#temp表。 但是,为了重复运行脚本,我仍然会收到错误,因为“这里已经是数据库中名为'#temp'的对象了。” 在第二个选择行中。 似乎丢弃表没有按照我的意愿生效。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM