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
For example:
select group_concat(v.name SEPARATOR ' ')
from (
select concat('rename table ', t.table_name, ' to ', substring(reverse(v.name), instr(reverse(v.name), '_') + 1, length(v.name)) name
from information_schema.tables t
where
table_schema = 'put_your_table_schema'
and table_name like '%_test'
) v;
substring(reverse.....) rather than simple replace(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