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]