有没有类似这样的语句:
alter table role add column name varchar (32) not null if not exists;

解决方案 »

  1.   

    if exists (select 1 from information_schema.columns where table_name='role' and column_name='name')
      

  2.   


    create procedure sp()
    begin
    if not exists (select 1 from information_schema.columns where table_name='role' and column_name='name') then
    ALTER  TABLE role add column name varchar (32) not null ;
    end if;
    end 
      

  3.   

    用 #2楼 的方法,先判断一下,然后再添加。create procedure sp()
    begin
    if not exists (select 1 from information_schema.columns where schema='db1' and  table_name='role' and column_name='name') then
    ALTER  TABLE role add column name varchar (32) not null ;
    end if;
    end