简体   繁体   English

需要MySQL 4来忽略ALTER TABLE错误

[英]Need MySQL 4 to ignore ALTER TABLE errors

I have a MySQL script which is executed automatically under certain conditions. 我有一个MySQL脚本,在某些条件下自动执行。 That script executes an ALTER TABLE command, because that column is needed in the database, but it may or may not have it... 该脚本执行ALTER TABLE命令,因为数据库中需要该列,但它可能有也可能没有...

Is it possible to make MySQL 4 execute the ALTER TABLE statement if the column doesn't exist or ignore the duplicate column error for this single command and allow the script execution to continue? 如果列不存在,是否可以使MySQL 4执行ALTER TABLE语句或忽略此单个命令的重复列错误并允许脚本执行继续?

ALTER [IGNORE] TABLE will only ignore certain errors, like duplicate key errors when adding a new UNIQUE index, or SQL mode errors. ALTER [IGNORE] TABLE将仅忽略某些错误,例如添加新UNIQUE索引时的重复键错误或SQL模式错误。

http://dev.mysql.com/doc/refman/4.1/en/alter-table.html http://dev.mysql.com/doc/refman/4.1/en/alter-table.html

More details about the "script" you are using would help to answer the question. 有关您正在使用的“脚本”的更多详细信息将有助于回答这个问题。 In python for example, the error would raise an exception which could then be caught and dealt with or ignored. 例如,在python中,错误会引发异常,然后可以捕获并处理或忽略该异常。

[EDIT] From the comment below, seems like you're looking for the mysql -f command line option. [编辑]从下面的评论,似乎你正在寻找mysql -f命令行选项。

You can first check the table schema before you attempt an addition of the column? 在尝试添加列之前,您可以先检查表模式吗? However , I strongly suspect the design where you need to add columns on the fly. 但是,我强烈怀疑设计在哪里需要动态添加列。 Something is not quite right. 有些事情不太对劲。 Can you explain the requirement in a little detail. 你能详细解释这个要求吗? I'm sure there are other cleaner way around this. 我相信还有其他更清洁的方法。

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

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