Duplicating Table

Re: [ewash] Duplicating Table

By Chris - March 22, 2010

Hi Ed,

There's no easy way to do this at the moment, but I can hopefully show you a trick with the MySQL Console plugin to avoid having to re-upload everything.

Firstly, create your two new Single Record sections, their fields, and then copy over all the non-upload content (by using two browser windows and copy-paste.)

Secondly, back up your database! You can make irreversible changes to your data with the MySQL Console plugin, and you could end up losing everything (or maybe just all your uploads.)

Finally, you'll need to run some MySQL queries to associate your uploads with your new tables...

Determine the record numbers for your two Options records. I'll assume they're 1 and 2, but you should check by looking in your browser's address bar when you click modify on them.

Go into MySQL Console (Admin > Plugins > "Run") and list some of the relevant uploads to get a feel for what you'll be changing:

SELECT * FROM cms_uploads WHERE tableName="options" AND recordNum IN (1, 2) LIMIT 100

This query will re-associate your Options record 1 uploads with a table called "new_options_1" (be sure to replace that with your new table name.) It'll affect all upload fields for that record, so we're assuming here that you haven't changed any of the field names.

UPDATE cms_uploads SET tableName="new_options_1" WHERE tableName="options" AND recordNum=1

This query will re-associate your Options record 2 uploads with record 1 in a table called "new_options_2":

UPDATE cms_uploads SET tableName="new_options_2", recordNum=1 WHERE tableName="options" AND recordNum=2

That should do it. Please let me know if you have any questions.
All the best,
Chris