下面的这样就可以,当时我直接执行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;  

解决方案 »

  1.   

    错误信息是什么?IF THEN在MYSQL中只能用到存储过程中。
      

  2.   

    可以更简单一点的写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 ;