存储过程判断该列是否存在,有则删除在添加

drop procedure if exists schema_change;  

delimiter ';;';  

create procedure schema_change() begin  

if exists (select * from information_schema.columns where table_name = 'sales_order' and column_name = 'has_sent') then  

        alter table sales_order drop column has_sent;  

end if;  

alter table sales_order add column has_sent boolean;  

end;;  

delimiter ';';  

call schema_change();  

drop procedure if exists schema_change; 

猜你喜欢

转载自blog.csdn.net/yuyeqianhen/article/details/89378018