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

来源:互联网 发布:windows的活动目录 编辑:程序博客网 时间:2024/04/28 16:33
  
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]