views:

78

answers:

1

is there any tools could help to convert innoDB table into NDB table? I want a tool help to replace all foreign key by trigger. Should I have to do it by manual for each FK?

A: 

I don't know if there are tools to let you do this.

You could always write a script in [your favourite scripting language] to do it.

It would work like:

(NB. I assume that every table is InnoDB and that you want to convert all of them. I also assume that there are no views in your db. If you have views then you have to issue SHOW FULL TABLES instead and treat only those rows for which the table type indicates that it is not a view. Also, this will not get rid of the indexes associated to foreign keys - you would need to do this part manually if you didn't want all of the indexes any more. Also, back up your database before you do anything! Although that goes without saying.)

  1. Create an empty array/list/whatever, $foreign_keys
  2. Issue SHOW TABLES
  3. For each table displayed:
    • Issue SHOW CREATE TABLE tablename
    • Do a regular expression search for /CONSTRAINT (.+) FOREIGN KEY/
    • For each match,
      • add the details of the foreign key on the same line to your array $foreign_keys;
      • issue a DROP FOREIGN KEY statement
  4. For each table, issue ALTER TABLE tablename ENGINE=NDB
  5. For each entry in your array $foreign_keys, issue a CREATE TRIGGER statement

Perhaps there actually are tools out there that will do it for you, but on the other hand this might be what you need to do if you don't want to do it manually.

Hammerite