数据库中已经有一个名为“#tmptable"的对象 [英] There is already an object named '#tmptable' in the database

查看:35
本文介绍了数据库中已经有一个名为“#tmptable"的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行存储过程,但我遇到了现有时态表的问题,但我只是创建了一次并用于另一部分代码

I´m trying to execute stored procedure but I get an issue of an existing temporal table, but I just create one time and use into another part of code

SELECT ...
INTO #tmpUnidadesPresupuestadas 
FROM proce.table1 

--Insertar in table src..
INSERT INTO table (
 ....) 
SELECT
....
FROM
    #tmpUnidadesPresupuestadas

我收到这条消息:

已经有一个名为的对象'#tmpUnidadesPresupuestadas' 在数据库中.

There is already an object named '#tmpUnidadesPresupuestadas' in the database.

我该如何解决?问候

推荐答案

临时表存在于整个当前会话中.如果您多次运行此语句,则该表已经存在.要么检测并截断它,要么在选择它之前 drop 如果它存在:

A temp table lives for the entirety of the current session. If you run this statement more than once, then the table will already be there. Either detect that and truncate it, or before selecting into it drop it if it exists:

DROP TABLE IF EXISTS #tmpUnidadesPresupuestadas

如果在 SQL Server 2016 之前,那么您就这样删除:

If prior to SQL Server 2016, then you drop as such:

IF OBJECT_ID('tempdb.dbo.#tmpUnidadesPresupuestadas', 'U') IS NOT NULL
  DROP TABLE #tmpUnidadesPresupuestadas; 

这篇关于数据库中已经有一个名为“#tmptable"的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆