0

What I'm trying to accomplish. My site is live, and I'm making some changes to it. When I'm ready to go live with the changes, I will essentially drop the old database (myFirstDb) and put the new one up(mySecondDb). BUT - I will want to keep a few of the tables from the live site(myFirstDb) - and bring them into the new database (mySecondDb). I know I can do this via phpMyAdmin - but that only allows one table at a time to be copied.

MY QUESTION: What kind of SQL Query in mySQL will allow me to define the tables to move from database one to database two. (Keeping the structure and data etc)

So here's what I have so far.

First off, is it possible to create a loop in mySql - SQL query? If so...

Could someone assist me proper syntax for creating an array in mySQL?

How would I go about creating the array in valid sql syntax?

// define array of table names here. <-- how to form this?

SET @table_name_array = ('tableFive', 'tableSeven', 'tableNine', 'tableFifteen', 'tableNineteen', 'tableNth', 'tableMaybeOneMore');

How would I go about looping thru that array in proper sql syntax?

// start loop thru each table name <-- how to write this?

My code so far

SET @database_name := 'myFirstDb';
SET @second_database_name := 'mySecondDb';

// define array of table names here. <-- how to form this?
SET @table_name_array = ('tableFive', 'tableSeven', 'tableNine', 'tableFifteen', 'tableNineteen', 'tableNth', 'tableMaybeOneMore');

// start loop thru each table name <-- how to write this?

SET @table_name := 'value';
SET @second_db_table_name := @table_name;

CREATE TABLE @second_db_table_name LIKE @table_name
ALTER TABLE @second_db_table_name DISABLE KEYS
INSERT INTO @second_db_table_name SELECT * FROM @table_name
ALTER TABLE @table_name ENABLE KEYS

//end loop here
Acts7Seven
  • 417
  • 1
  • 6
  • 14

0 Answers0