简体   繁体   中英

MySQL: ALTER IGNORE TABLE with DROP INDEX

I have many databases and in each I have table names . In some I have UNIQUE KEY named name1 and in others the same UNIQUE KEY is named name2 . I want to standard this name so I prepared 3 queries to run on each database:

ALTER IGNORE TABLE `names`
    DROP INDEX `name1`;
ALTER IGNORE TABLE `names`
    DROP INDEX `name2`;
ALTER TABLE `names`
    ADD UNIQUE `new_name` (`name`, `surname`);

But I got error:

SQL Error (1091): Can't DROP 'name1'; check that column/key exists

How can I make one set of queries to run on each database?

You can attempt to ignore errors if you're executing your SQL script file from command line:

mysql -f -u username -p password -e 'source script.sql'

EDIT

Thanks to Ike, the correct way to do this is:

mysql -f -u username -p password < script.sql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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