下面的这样就可以,当时我直接执行sql语句,提示语法错误 select @num:=count(*) from information_schema.columns where table_schema='库名' and table_name='表名' and COLUMN_NAME='列名'; if @num <=0 then alter table 表名 add 新增的字段名 数据类型定义; end if;
可以更简单一点的写create procedure procTest() begin if not exists(select 1 from information_schema.columns where table_schema='库名' and table_name='表名' and COLUMN_NAME='列名') then alter table 表名 add 新增的字段名 数据类型定义; end if; end ;
begin
if not exists(select 1 from information_schema.columns where table_schema='库名' and table_name='表名' and COLUMN_NAME='列名') then
alter table 表名 add 新增的字段名 数据类型定义;
end if;
end ;