0

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?

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
kuba
  • 3,670
  • 3
  • 31
  • 41
  • So what is the question? How to ignore error, or how to run query in each database? – azat Mar 10 '11 at 12:44

1 Answers1

3

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
JamesHalsall
  • 13,224
  • 4
  • 41
  • 66
  • 1
    Actually that will not work if there is more than one error. It will abort after the first error. The proper way to ignore errors in script.sql is: `mysql -f -u username -p password < script.sql` – Ike Walker Mar 10 '11 at 15:26