MySQL

How to set prefix to multiple tables at one time

Set Max Length for Group Concatenation

SET group_concat_max_len = 6144;

Generate the SQL

SELECT 
    CONCAT('RENAME TABLE ', GROUP_CONCAT('`', TABLE_SCHEMA, '`.`', TABLE_NAME, '` TO `', TABLE_SCHEMA, '`.`rgbis_', TABLE_NAME, '`')) AS q
FROM 
    `information_schema`.`Tables` WHERE TABLE_SCHEMA='target_database';

Once above SQL generated, copy & paste in your SQL editor, and execute it.

Leave a Reply

Your email address will not be published. Required fields are marked *

8 + 7 =