如题

解决方案 »

  1.   

    if exists(select 1 from syscolumns where id=object_id('表a') and name ='item')
    print '有'
      

  2.   

    if exists(select 1
    from syscolumns 
    where name = 'item' and id = object_id('a'))
      print '存在'
      

  3.   

    if exists (select 0 from syscolumns where id=object_id('a') and name='item')
    print '有'
      

  4.   


    --这样?
    if exists(select 1 from sysobjects o, syscolumns B 
       where o.id = B.id and O.type = 'U' and o.name = '表A' and B.name = 'item')
    begin
      print '存在'
    end
    else
    print '不存在'
      

  5.   

    if exists(select 1 from syscolumns where id=object_id('表a') and name ='item') 
    print '有' 
    支持这个
      

  6.   

    select * from sys.columns
    where [name] = 'xxxx'
      

  7.   


    ----------------------------------------------------------------------------------------------
    if exists(select * from sys.objects o, sys.columns B 
       where o.object_id = B.object_id and O.type = 'U' and o.name = 'a' and B.name = 'item')
    begin
      print 'you'
    end
    else
    print 'wu'
    结果是:wu
    ----------------------------------------------------------------------------------------------
    if exists(select * from sys.objects o, sys.columns B 
       where o.object_id = B.object_id  and o.name = 'a' and B.name = 'item')
    begin
      print 'you'
    end
    else
    print 'wu'
    结果是:you
    ----------------------------------------------------------------------------------------------
    IF EXISTS (SELECT * FROM sys.objects O,sys.columns C 
       WHERE O.object_id = OBJECT_ID('a') AND C.object_id=O.object_id and C.name = 'item')
    print 'you'
    else
    print 'wu'
    结果是:wu
    ----------------------------------------------------------------------------------------------
    IF EXISTS (SELECT * FROM sys.objects O,sys.columns C 
       WHERE O.object_id = OBJECT_ID('a') AND C.object_id=O.object_id and C.name = 'item')
    begin
      print 'you'
    end
    else
    print 'wu'
    结果是:wu
    ----------------------------------------------------------------------------------------------
    IF EXISTS (SELECT * FROM sys.objects O,sys.columns C 
       WHERE O.object_id = OBJECT_ID('a')  and C.name = 'item')
    begin
      print 'you'
    end
    else
    print 'wu'
    结果是:you
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      

  8.   

    前提是在表a中确实存在字段item