SQL判断临时表是否存在
1个回答
展开全部
判断临时表是否存在Way 1if(exists(select name from tempdb..sysobjects where name like'%temptab%' and type='U'))
drop table #temptabWay 2 if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#tempcitys') and type='U')
drop table #tempcitysWay 3IF OBJECT_ID('tempdb..#') IS NOT NULL
DROP TABLE #OBJECT_ID此函数返回数据库对象标识号判断数据库里有没有存在PerPersonData这样一张表if exists (select * from sysobjects where objectproperty(object_id('PerPersonData'),'istable') = 1)OBJECTPROPERTY:返回当前数据库中对象的有关信息。1表“真”。同样可以写成OBJECTPROPERTY(id, isUserTable) = 1 if exists (select * from sysobjects where id = object_id(N'PerPersonData') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table 'PerPersonData'判断试图是否存在 if exists (select * from sysobjects where id = object_id(N‘[dbo].[ESTMP]‘)
drop table #temptabWay 2 if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#tempcitys') and type='U')
drop table #tempcitysWay 3IF OBJECT_ID('tempdb..#') IS NOT NULL
DROP TABLE #OBJECT_ID此函数返回数据库对象标识号判断数据库里有没有存在PerPersonData这样一张表if exists (select * from sysobjects where objectproperty(object_id('PerPersonData'),'istable') = 1)OBJECTPROPERTY:返回当前数据库中对象的有关信息。1表“真”。同样可以写成OBJECTPROPERTY(id, isUserTable) = 1 if exists (select * from sysobjects where id = object_id(N'PerPersonData') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table 'PerPersonData'判断试图是否存在 if exists (select * from sysobjects where id = object_id(N‘[dbo].[ESTMP]‘)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询