您的位置:首页 > 数据库

SQL server 2000 如何判断临时表是否存在 .

2012-03-16 14:37 281 查看
1.判断一个临时表是否存在

if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#tempcitys') and type='U')

drop table #tempcitys

注意tempdb后面是两个. 不是一个的

---临时表

if exists(select * from tempdb..sysobjects where name like ‘#tmp1%‘)

drop table #tmp1



if exists( select * from tempdb..sysobjects where id=OBJECT_ID('tempdb..#tmp') )

drop table #tmp1

--视图

if exists (select * from sysobjects where id = object_id(N‘[dbo].[ESTMP]‘)

and OBJECTPROPERTY(id, N‘IsView‘) = 1)

drop view ESTMP

判断表是否存在

if exists (select * from sysobjects where id = object_id(N'[dbo].[phone]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[phone]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: