0

Now I want to change the MySQL 8.0.24 table name in flyway, this is the sql command:

RENAME TABLE package_exception TO package_event;

how to handle the table package_exception not exists? how to handle the package_event already exists? I have already tried this:

ALTER TABLE IF EXISTS package_exception RENAME TO package_event;

but shows error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF EXISTS package_exception RENAME TO package_event' at line 1
Shadow
  • 33,525
  • 10
  • 51
  • 64
Dolphin
  • 29,069
  • 61
  • 260
  • 539
  • 2
    [MariaDB-10.5](https://dbfiddle.uk/?rdbms=mariadb_10.5&fiddle=14ad17665233cb35e4fd7e4e0da4532f) supports such a [syntax](https://mariadb.com/kb/en/alter-table/), however [MySQL-8.0](https://dev.mysql.com/doc/refman/8.0/en/alter-table.html) does not. – danblack Apr 26 '22 at 07:55
  • I think flyway itself doesn't really care about the syntax you place in scripts hence your question essentially boils down to "how to rename the table in your version of mysql"? Can you please specify your version of mysql? – Mark Bramnik Apr 26 '22 at 07:58
  • 1
    Also you can try: `ALTER TABLE package_exception RENAME package_event;` as specified in https://dev.mysql.com/doc/refman/8.0/en/rename-table.html – Mark Bramnik Apr 26 '22 at 08:00
  • Possible duplicate of [this](https://stackoverflow.com/q/67008422/642706) and [this](https://stackoverflow.com/q/16837134/642706). – Basil Bourque Apr 26 '22 at 08:08

0 Answers0