我需要自己删除临时表,因为在一个操作流程内,我只需要将数据在3个临时表来回滚即可,比如#t1有了数据,select into #t2后,再次需要select into#t1,因此在这中间我需要检查这几个临时表是否存在,若存在就删除。
但是obejct_id(\'#t1\')或者exists(select name from tempdb.dbo.sysobjects where name=\'#t1\')都有些问题。
这需要怎么写?有啥注意事项?
现在搞清楚了情况,比较诡异
如果一批sql中没有用go,在一个地方用if object_id(\'tempdb.dbo.#t1\') is not null drop table #t1
的确删除了这个表,但是紧接的一个select into #t1 又说表还存在,可能是io之间的不同步造成的。这样的话,这select into #t1前加一个go就可以了。
问题是,如果这是一个存储过程的话,中间是无法加go的!!!
这个怎么办?如果每个临时表都是几个G的话,这样的空间浪费太浪费了。