I know how to run
RENAME TABLE onetable_test TO onetable;
But is there a method to rename many tables with a pattern and don't write a lot of code like
RENAME TABLE onetable_test TO onetable;
RENAME TABLE twotable_test TO twitable;
RENAME TABLE threetable_test TO threetable;
...
I am using mysql.
Thanks!
Use below stored procedure ::
CREATE
DELIMITER ;
Replace table_schema with your table_schema name.
A slight modification on @ravnur's answer:
Useful when you want to rename your Wordpress tables from the default prefix of
wp_
toblog_
(for example). Copy and paste the output of that command into the mysql shell or phpMyAdmin.For example:
substring(reverse.....)
rather than simplereplace(v.name, '_test', '')
used because we need to be sure that we will replace only_test
occurrences only at the end of the string.Hope it helps
I wanted to update what worked for me since this post is pretty old. I needed to add the ` mark before and after the table names. And don't forget to add the last ; because this can sometimes throw a syntax error.