部分代码需要在两个临时表之间进行交换,当我删除一个表并重用它时我不能
create table #temp (id int)
create table #swap (id int)
drop table #temp
select * into #temp from #swap
drop table #swap
drop table #temp
我收到此错误
消息2714,级别16,状态1,行6数据库中已存在名为“#temp”的对象。
只需改变一下你的逻辑流程。如果重要的是当#temp
发生时INSERT
是空的,这应该做你需要的。
create table #temp (id int)
create table #swap (id int)
<Add loop logic here>
truncate table #temp
insert #temp(id)
select id from #swap
<Close out loop logic>
drop table #swap
drop table #temp
我还明确了列名。 SELECT *
是一个等待在生产代码中发生的事故。