300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > mysql查询临时表是否存在_[转]SQL判断临时表是否存在

mysql查询临时表是否存在_[转]SQL判断临时表是否存在

时间:2023-10-30 18:02:09

相关推荐

mysql查询临时表是否存在_[转]SQL判断临时表是否存在

判断临时表是否存在

Way 1

if(exists(select name from tempdb..sysobjects where name like'%temptab%' and type='U'))

drop table #temptab

Way 2

ifexists(select*fromtempdb.dbo.sysobjectswhereid=object_id(N'tempdb..#tempcitys')andtype='U')

droptable#tempcitys

Way 3

IF 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

ifexists(select*fromsysobjectswhereid=object_id(N'PerPersonData')andOBJECTPROPERTY(id,N'IsUserTable')=1)

droptable'PerPersonData'

判断试图是否存在

ifexists(select*fromsysobjectswhereid=object_id(N‘[dbo].[ESTMP]‘)

andOBJECTPROPERTY(id,N‘IsView‘)=1)

dropviewESTMP

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。