tags:

views:

47

answers:

1

I have the following query:
ALTER TABLE table CHANGE 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?

A: 

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

codaddict