change MySQL field type if field exists
I have the following query:
ALTER TABLE table CHAN开发者_开发百科GE field1 field1 INTEGER
Is there anyway that I can add some sort of if exists to this statement so that MySQL will make sure that field 1 exists before attempting to change its field type?ALTER TABLE
in MySql does not take an IF EXISTS
clause.
You can do a
describe table
or
show columns from table
to get the list of all columns and then check if field1 is present before you do a ALTER TABLE
精彩评论