簡體   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