开发者

change MySQL field type if field exists

开发者 https://www.devze.com 2022-12-15 07:32 出处:网络
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 fiel

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

0

精彩评论

暂无评论...
验证码 换一张
取 消