MySQL 4 needs to ignore ALTER TABLE errors

I have a MySQL script that runs under certain conditions. This script executes the ALTER TABLE command because this column is needed in the database, but it may or may not have it ...

Is it possible to force MySQL 4 to execute the ALTER TABLE statement if the column does not exist or to ignore the duplicate column error for this single command and allow script execution to continue?

+4
source share
2 answers

ALTER [IGNORE] TABLE will ignore certain errors, such as duplicating key errors when adding a new UNIQUE index or errors in SQL mode.

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

More information about the "script" you are using will help answer the question. For example, in python, an error would throw an exception, which could then be caught, processed, or ignored.

[EDIT] From the comment below, it seems that you are looking for the mysql -f command line option.

+3
source

Can you check the table schema first before trying to add a column? However, I strongly suspect a design where you need to add columns on the fly. Something is wrong. Could you explain this requirement in detail. I am sure there are other cleaner ways too.

0
source

All Articles