如何判断数据库的表1中存在ID列

解决方案 »

  1.   

    你的ID列是什么意思?.
    自增列?.主键?..还是列名仅是ID而已?
      

  2.   

    如果ID列的意思是名为id的列
    if exists (select 1 from syscolumns where id=object_id('表1') and name='ID')
      print '存在'
    else
      print '不存在'
      

  3.   


    if col_length('表名', '列名') is null
    print '不存在'
      

  4.   

    if exists(select * from syscolumns where id = object_id('abc') and name = 'id' )
        print 'exists'
    else
        print 'None'
      

  5.   


    if exists(select 1 from syscolumns where id=object_id('表1') and name='id')
       print '存在'
    else
       print '不存在'
      

  6.   

    如果ID列的意思是自增列 
    if exists (select 1 from syscolumns where id=object_id('表1') and COLUMNPROPERTY (id,name,'IsIdentity')=1 ) 
      print '存在' 
    else 
      print '不存在'