IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects WHERE id =object_id('tempdb.dbo#temp))
DROP TABLE tempdb.#tempcreate table #temp(...)select * into #temp from .....我在存储过程中这样写。
执行的时候 这句报#tempe对象已经存在。请假解决方法
DROP TABLE tempdb.#tempcreate table #temp(...)select * into #temp from .....我在存储过程中这样写。
执行的时候 这句报#tempe对象已经存在。请假解决方法
存在用insert into #temp select * from .....
是会创建表的,请应用insert into 表 select * from ...
IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects WHERE id =object_id('tempdb.dbo#temp))
DROP TABLE tempdb.#temp create table #temp(...) insert into #temp
select * from .....
和
select * into ...都会创建表,出现重复错误的提示是肯定的
这两句都是创建表
用这个判断是否存在,
select * from tempdb.sys.objects where object_id = object_id('tempdb..#tempTable1')
如果存在
drop table #tempTable1
select * into #temp from .....这句是在临时表不存在时才可以select
因为你已创建临时表 create table #temp(...)
方案一:select * into #temp from .....可改为insert into #temp select * from ...
方案二:删掉create table #temp(...)
--测试通过
--临时表存在则先删除
if object_id('tempdb..#temp','U') is not null
drop table #temp;
--创建临时表
create table #temp
(
test char(2)
)