试一下! if not exists ( select * from syscolumns where name='字段名' and [id]=(select [id] from sysobjects where name='表名') ) begin alter table [表名] add columns......... end
You can not only use a single statement to do this. The store procedure within mysql can satisfy your demand. For example. Tablename :t Columnname:idDELIMITER $$CREATE PROCEDURE `t1`.`sp_t`() BEGIN if not exists (select 1 from t where id = 2) then insert into t(id) values (2); else begin end; end if; END$$DELIMITER ;
if not exists (
select * from syscolumns where name='字段名'
and [id]=(select [id] from sysobjects where name='表名')
)
begin
alter table [表名] add columns.........
end
The store procedure within mysql can satisfy your demand.
For example.
Tablename :t
Columnname:idDELIMITER $$CREATE PROCEDURE `t1`.`sp_t`()
BEGIN
if not exists (select 1 from t where id = 2) then
insert into t(id) values (2);
else
begin end;
end if;
END$$DELIMITER ;