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