码迷,mamicode.com
首页 > 数据库 > 详细

liquibase判断mysql表字段是否存在

时间:2016-11-29 23:48:20      阅读:366      评论:0      收藏:0      [点我收藏+]

标签:mysql判断字段是否存在

背景:今天在部署sql代码的时候,发现以前一直使用的判断字段存在的方式不起作用了,如下:

<preConditions onFail="MARK_RAN" >
        <not>
            <columnExists schemaName="${schema.name}" tableName="prize" columnName="reward_service_category" />
        </not>
    </preConditions>



在网上找了好久方法,liquibase的资料太少,最后决定使用存储过程去判断,这种方法确实好用。


delimiter //
create procedure add_more_to_logins() begin    
    if not exists(select * from information_schema.COLUMNS
              where table_name = ‘a‘ AND column_name = ‘b‘ and table_schema = database()) THEN        
        alter table a add `is_mobile` tinyint(1) null after reason;
    end if;
    
END;
//
delimiter ;

本文出自 “Victor的奋斗历程” 博客,请务必保留此出处http://victor2016.blog.51cto.com/6768693/1877797

liquibase判断mysql表字段是否存在

标签:mysql判断字段是否存在

原文地址:http://victor2016.blog.51cto.com/6768693/1877797

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!