IF (SELECT object_id('TempDB.#jobsconsumed')) IS NULL
BEGIN
DROP Table #jobsconsumed
END
上面的代码将进入开始条款,只有当不是Temptable存在..
检查和下降不是Temptable,正确的方法是低于
IF object_id('Tempdb..#test') is Not null
is same as
IF object_id('Tempdb.dbo.#test') is Not null
Drop Table #test
有没有必要在这种情况下,由于IF将执行立即声明
s对临时表的架构方面OME测试..
use tempdb;
create schema hr
create table hr.#t(c int) --this will work
create table #t(c int) --this will fail
create table #t1 --no schema ,so it will create a temp table in DBO Schema by default.
--To drop the table
drop table #t --this will drop across all schemas
我想你应该尝试两点:'TempDB的..#jobsconsumed' – HoneyBadger
什么是2点呢? – whatwhatwhat
可能'不是NULL'是你真正想要的逻辑。为什么要删除不存在的内容? –