简体   繁体   English

mysql 5.6 alter table drop列(如果存在)

[英]mysql 5.6 alter table drop column if exists

i'm asking this question after googling with no luck. 我没有运气就谷歌搜索后问这个问题。 it has been asked before on SOF but that's long ago MySQL Alter syntax to drop a column if it exists . 在SOF上曾经有人问过它,但是很久以前, MySQL Alter语法删除了一个存在的列 Hope things have changed since. 希望此后一切都变了。

Is there a straight forward way to drop a column in table if it exists. 有没有直接的方法可以将表中的列删除(如果存在)。

I'm using MySql 5.6, i would like to wrap this alter statement around an if to avoid any issue if the script runs twice: 我正在使用MySql 5.6,如果脚本运行两次,我想将if语句包装在if周围,以避免出现任何问题:

ALTER TABLE xyz DROP COLUMN abc, ADD COLUMN ghi DATE NOT NULL AFTER column4; ALTER TABLE xyz DROP COLUMN abc,ADD COLUMN ghi DATE NOT NULL after column4;

Thanks 谢谢

You may check if column exists and after perform the other operations. 您可以检查列是否存在以及执行其他操作之后。

See here: MySQL, Check if a column exists in a table with SQL 参见此处: MySQL,使用SQL检查表中是否存在列

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM