if(object_id('tempdb..#t') is not null)
drop table #t
select * into #t from t
if(object_id('tempdb..#t') is not null)
drop table #t
select * into #t from t
提示:数据库中已存在名为 '#t' 的对象。
已经删除了为什么还提示已存在名为 '#t' 的对象。
...全文
10119打赏收藏
存储过程中使用临时表的问题
在一个存储过程中为什么这样写不行?因为我不想用太多个临时表,所以要删除了再插入数据,这样不行吗? if(object_id('tempdb..#t') is not null) drop table #t select * into #t from t if(object_id('tempdb..#t') is not null) drop table #t select * into #t from t 提示:数据库中已存在名为 '#t' 的对象。 已经删除了为什么还提示已存在名为 '#t'
[Quote=引用 1 楼 pt1314917 的回复:]
SQL code
if(object_id('tempdb..#t') is not null)
drop table #t
select * into #t from a
go --注意这里
if(object_id('tempdb..#t') is not null)
drop table #t
select * into #t from a
[/Quote]
if(object_id('tempdb..#t') is not null)
drop table #t -------------------------->>没有执行
select * into #t from t ------------------->>所以会提示#t已经存在
if(object_id('tempdb..#t') is not null)
drop table #t
select * into #t from t
if(object_id('tempdb..#t') is not null)
drop table #t
select * into #t from a
go --注意这里
if(object_id('tempdb..#t') is not null)
drop table #t
select * into #t from a