mardi 6 octobre 2020

MYSQL - Check if table exists before alter table

I need query to update all tables and set ENGINE = INNODB To many databases. But some of the databases have not all tables since other databases have more tables.

So the problem is

ALTER TABLE `ads` ENGINE = INNODB;
ALTER TABLE `modules` ENGINE = INNODB;
ALTER TABLE `ad_extras` ENGINE = INNODB;

Throw error when table modules did not exists

I see that I cannot make direct IF statement I tried:

IF EXISTS (SHOW TABLES LIKE 'modules') BEGIN
ALTER TABLE `modules` ENGINE = INNODB;
END IF

But it throws Unrecognized statement type (near IF EXISTS)

Any ideas?

Aucun commentaire:

Enregistrer un commentaire