--先判断列是否存在,不存在赠新增(假设列名为aa if not exists (select * from syscolumns where name='aa' and id in(select id from sysobjects where name='表名')) begin alter table 表名 ADD [aa] [int] NOT NULL IDENTITY (1, 1) end GO
select id from sysobjects where name='表名' 这个不是返回表的ID吗,因该就一个值啊?,那这ID与新建的列名有什么关系
add id int identity(1,1)
ALTER TABLE t
ADD id int identity(1,1)
if not exists (select * from syscolumns where name='aa' and id in(select id from sysobjects where name='表名'))
begin
alter table 表名 ADD [aa] [int] NOT NULL IDENTITY (1, 1)
end
GO