sql-server-2012 - 删除临时表但已经建立'数据库中已经有一个名为'#temp'的对象'
问题描述
当我删除一个表并重用它时,部分代码需要在两个临时表之间进行交换,我不能
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 *
是在生产代码中等待发生的事故。
推荐阅读
- jenkins - 使用从另一个 Groovy 文件加载的枚举(Jenkins Pipeline 问题)
- neo4j - 配置关系时如何调试无效输入密码查询?(Neo4j OGM)
- javascript - 如何将 2 lambda 结果连接成一个数组
- javascript - 如何防止 javascript 中 %WINDIR%\\system32\\netsh.exe 中的 \\n 引起的新行
- mysql - 如何在一个查询中使用表中的选定值并将其用于另一个表中的下一个选择?
- java - 为什么我从 OkHttp 请求中收到协议错误?
- python - 为python中的列表定义数值稳定的sigmoid函数的最佳方法
- css - 响应卡 bootstrap4
- powerbi - 用于合并的多列行的切片器
- javascript - 画布动画性能不佳,线条很多