已知表名 table1  
有该表显示表名     无则为空

解决方案 »

  1.   

    if object_id('table1','U') is not null
    print '有'
    else
    print '无'
      

  2.   

    if object_id('table1','U')is not null
    print 'table1'
    else
    print NUll
      

  3.   

    if object_id('table1   ') is not null
    print 'table1   '
      

  4.   

    select case when object_id('table1')>0 then '存在table1' else '不存在table1' end
      

  5.   

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

  6.   

    SELECT CASE WHEN OBJECT_ID('table1')>0 THEN '存在table1' END
    /*
    ----------
    存在table1(1 行受影响)
    */SELECT CASE WHEN OBJECT_ID('table12121')>0 THEN '存在table1' END
    /*
    ----------
    NULL(1 行受影响)
    */
      

  7.   


    DECLARE @TableName nvarchar(100)
    SET @TableName = 'table1'
    SELECT CASE WHEN OBJECT_ID(@TableName) IS NOT NULL THEN @TableName END
      

  8.   


    if(Exists(select 1 from sysobjects where name='tablename'and type='U')) print '存在'
    else print '不存在'
      

  9.   

    use 数据库名
    go
    if exists(select * from sysobjects where [name]='表名')
    drop table 表名
    go