给出一个表名的一部分,怎么能判断数据库中是否包含这样的表?

解决方案 »

  1.   

    --sql2005
    select * from sys.tables where name like '%表名一部分%'
      

  2.   


    if exists(select 1 from sysobjects where xtype='u' and [name]='a')
    print '存在表a'
    else 
    print '不存在表a'--2005是xtype,2000是type
      

  3.   

    那就这样if exists(select 1 from sys.tables where [name] = 'a')
    print '存在表a'
    else 
    print '不存在表a'
      

  4.   

    为了保持和2005的兼容性,2000也有xtype了,某个补丁(可能sp3)的版本之后,所以你可以放心的用
      

  5.   


    SQL 2000,2005,2008 通用,刚试过了
    select * from sysobjects where name like '%表名一部分%' and 
    XTYPE='u' order by name
      

  6.   

    SELECT * FROM sys.sysobjects WHERE xtype='U' AND name like '%表名的一部分%'
      

  7.   

    补充一下:
    use 你要查询的数据库名称
    select name crdate from sys.tables
    where xtype='u'
    order by name