IF (SELECT count(*) FROM sys.columns WHERE object_id = 
                                          (SELECT object_id FROM sys.tables WHERE name = '表1') 
                and name = '列1') = 0......

解决方案 »

  1.   

    我想修改数据库中的一个表 添加一个字段 比如说表A,添加X字段,类型是float,先检查一下时候存在这个字段
    if exists(select * from A where ???????????
    以下怎么写呀
      

  2.   

    1 楼foolishchao(亚超)回复于 2002-04-16 09:57:59 得分 20if   exists   (select   *   from   syscolumns   where   id=object_id('TABLE1')   and   name='FIELD1')   print   'exists'
    Top2 楼wonder01(一可)回复于 2002-04-16 10:00:22 得分 0 你要从系统表中查找,在sysobjects表中查到对象的id,根据id到syscolumns中查找字段。比如你要找到一个test表的所有字段名:   
      select   name   from   syscolumns   where   id   in(select   id   from   sysobjects   where   name='test')     
      我想达到你的要求不难了吧!
      

  3.   

    我想修改数据库中的一个表 添加一个字段 比如说表A,添加X字段,类型是float,先检查一下时候存在这个字段
    if exists(select * from A where ???????????
    以下怎么写呀
      

  4.   

    select count(*) from syscolumns
    where id   = (select id from sysobjects where type='U' and name='你的表名')
    and   name = '你要判断的字段名'
      

  5.   

    if exists(select 1 from syscolumns where id = object_id('yourtable') and name = 'yourfield')