Liquibase to determine if a MySQL table field exists

Source: Internet
Author: User

Tag: MySQL Determines whether a field exists

Background: Today, when deploying SQL code, it is not possible to discover the way in which a previously used judgment field exists, as follows:

<preconditions onfail= "Mark_ran" >
<not>
<columnexists schemaname= "${schema.name}" tablename= "Prize" columnname= "Reward_service_category"/>
</not>
</preConditions>



On the internet to find a long time method, liquibase too little data, and finally decided to use stored procedures to judge, this method is really good.


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;

This article is from the "Victor's Struggle" blog, please be sure to keep this source http://victor2016.blog.51cto.com/6768693/1877797

Liquibase to determine if a MySQL table field exists

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.