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)
可以这么做if not exists(select 1 from INFORMATION_SCHEMA.COLUMNS where Table_Name='表名' AND Column_Name='列名') alter table 表名 ADD 列名 VARCHAR(20) NULL
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原理 查询是否有该表的列名存在。不存在就添加。
if not exists(select 1 from INFORMATION_SCHEMA.COLUMNS where Table_Name='表名' AND Column_Name='列名') alter table 表名 ADD 列名 VARCHAR(20) NULL
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)
alter table 表名 ADD 列名 VARCHAR(20) NULL
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原理 查询是否有该表的列名存在。不存在就添加。
alter table 表名 ADD 列名 VARCHAR(20) NULL