create table #testTable1
(
c1 int
) go
if exists(select name from tempdb.dbo.sysobjects where name like '#testTable1%' and type='U')
Begin
--如果表已经存在,执行相应操作
SELECT '存在 '
END
ELSE
Begin
--如果表不存在,执行相应操作
SELECT '不存在'
end create table c(id int)if exists(select * from dbo.sysobjects where
id = object_id(N'c') and OBJECTPROPERTY(id,N'IsUserTable')=1)
Begin
--如果表已经存在,执行相应操作
SELECT '存在 '
END
ELSE
Begin
--如果表不存在,执行相应操作
SELECT '不存在'
end
(
c1 int
) go
if exists(select name from tempdb.dbo.sysobjects where name like '#testTable1%' and type='U')
Begin
--如果表已经存在,执行相应操作
SELECT '存在 '
END
ELSE
Begin
--如果表不存在,执行相应操作
SELECT '不存在'
end create table c(id int)if exists(select * from dbo.sysobjects where
id = object_id(N'c') and OBJECTPROPERTY(id,N'IsUserTable')=1)
Begin
--如果表已经存在,执行相应操作
SELECT '存在 '
END
ELSE
Begin
--如果表不存在,执行相应操作
SELECT '不存在'
end
if object_id('tempdb..#临时表名') is not null
--存在
else
--不存在实表
if object_id('库..表名') is not null
--存在
else
--不存在
--------------
也可以查sysobjects表