需要 MySQL 4 来忽略 ALTER TABLE 错误

发布于 2024-07-14 05:39:08 字数 179 浏览 6 评论 0原文

我有一个 MySQL 脚本,它在某些条件下自动执行。 该脚本执行 ALTER TABLE 命令,因为数据库中需要该列,但它可能有也可能没有......

是否可以让 MySQL 4 执行 ALTER TABLE< /code> 语句(如果列不存在)或忽略此单个命令的重复列错误并允许脚本继续执行?

I have a MySQL script which is executed automatically under certain conditions. That script executes an ALTER TABLE command, because that column is needed in the database, but it may or may not have it...

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉殇 2024-07-21 05:39:08

ALTER [IGNORE] TABLE 只会忽略某些错误,例如添加新 UNIQUE 索引时的重复键错误或 SQL 模式错误。

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

有关您正在使用的“脚本”的更多详细信息将有助于回答该问题。 例如,在 python 中,错误会引发异常,然后可以捕获并处理或忽略该异常。

[编辑] 从下面的评论来看,您似乎正在寻找 mysql -f 命令行选项。

ALTER [IGNORE] TABLE will only ignore certain errors, like duplicate key errors when adding a new UNIQUE index, or SQL mode errors.

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.

[EDIT] From the comment below, seems like you're looking for the mysql -f command line option.

逆光下的微笑 2024-07-21 05:39:08

您可以在尝试添加列之前先检查表架构吗? 但是,我强烈怀疑您需要动态添加列的设计。 有些事情不太对劲。 您能详细解释一下这个要求吗? 我确信还有其他更清洁的方法可以解决这个问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文