rt,如果不存在某列,则添加该列
if not exists(select ? //后面不清楚

解决方案 »

  1.   


    if not exists(select 1 from syscolumns where name='col_name' and id= object_id('table_name'))
    alter table table_name add col_name varchar(32)
      

  2.   

    可以这么做if not exists(select 1 from INFORMATION_SCHEMA.COLUMNS where Table_Name='表名' AND Column_Name='列名')
        alter table 表名 ADD 列名 VARCHAR(20) NULL 
       
      

  3.   


    if not exists(select top 1 * from syscolumns where name='列名' and id=(select top 1 id from sysobjects where name='表名' and xtype='u'))
    begin
    alter table 表名
    add 列名 类型
    end原理 查询是否有该表的列名存在。不存在就添加。
      

  4.   

    if not exists(select 1 from INFORMATION_SCHEMA.COLUMNS where Table_Name='表名' AND Column_Name='列名')
      alter table 表名 ADD 列名 VARCHAR(20) NULL