当前位置:Gxlcms > 数据库问题 > liquibase判断mysql表字段是否存在

liquibase判断mysql表字段是否存在

时间:2021-07-01 10:21:17 帮助过:83人阅读

背景:今天在部署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判断字段是否存在

人气教程排行