How do I retain the MySQL old table after renaming it?

They have: 488 posts

Joined: Feb 2000

alter table table_name rename new_table_name

How do I keep a copy of the old table?

Thanks.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I did a short search on http://mysql.com and didn't find any info on using a query to make a copy of a table (seems useful though). You could do this using a server-side language (I recommend phpMyAdmin).

If you want to back up the table try: http://www.mysql.com/doc/B/A/BACKUP_TABLE.html

Or, you could back up the table, then rename it. Then restore the backed up data...

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 488 posts

Joined: Feb 2000

Yes I am using phpMyAdmin but I can't find any code regarding backing up the old table and at the same rename the table.

I will use the second option you suggested until I can find it.

Thanks Mark.

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

I don't think there's an easy (built in) way to do this. To do this in Transact-SQL you would have to create the table first, copy all data from the table you are going to rename, and then rename the table.

PJ | Are we there yet?
pjboettcher.com

They have: 488 posts

Joined: Feb 2000

Thanks Peter,

I will try it also and see which is the best method to use.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

what version do you have?
I'm running version 3.23.32

select a table, and look at the properties page
at the bottom it should say "Copy table to:" then have a textbox and two radio buttons "Structure only" and "Structure and data".

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 488 posts

Joined: Feb 2000

I am using ver 3.23.27 the actual syntax for rename table ver 3.23.27 and above is.

rename table_name to new_table_name

Thanks, I will try your suggestion.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

What version of phpMyAdmin are you using? If you view the ChangeLog, the ability to copy a table was added in version 1.3.1

They have: 488 posts

Joined: Feb 2000

I am using ver 2.0.1

Yes! it's under "Properties = copy/rename table" I am able to duplicate/copy the complete table and also rename it.

Thanks a lot Mark.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.