34,588
社区成员
发帖
与我相关
我的任务
分享
if(Exists(select 1 from sysobjects where name='tablename'and type='U')) print '存在'
else print '不存在'
DECLARE @TableName nvarchar(100)
SET @TableName = 'table1'
SELECT CASE WHEN OBJECT_ID(@TableName) IS NOT NULL THEN @TableName END
SELECT CASE WHEN OBJECT_ID('table1')>0 THEN '存在table1' END
/*
----------
存在table1
(1 行受影响)
*/
SELECT CASE WHEN OBJECT_ID('table12121')>0 THEN '存在table1' END
/*
----------
NULL
(1 行受影响)
*/
select case when object_id('table1')>0 then '存在table1' else '不存在table1' end
if object_id('table1 ') is not null
print 'table1 '
if object_id('table1','U')is not null
print 'table1'
else
print NUll
if object_id('table1','U') is not null
print '有'
else
print '无'