以下のストアド プロシージャを使用::
DELIMITER $$
作成
PROCEDURE `Rename_Tables`()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE tableName VARCHAR(50);
DECLARE newTableName VARCHAR(70);
DECLARE t_query VARCHAR(500);
DECLARE cur1 CURSOR FOR SELECT table_name FROM information_schema.tables WHERE table_name LIKE '%table_test' AND table_schema='test' ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cur1;
read_loop: LOOP
FETCH cur1 INTO tableName;
IF done THEN
LEAVE read_loop;
END IF;
SET newTableName = SUBSTRING(tableName, 1,LOCATE('_',tableName)-1);
SET t_query = CONCAT('RENAME TABLE ', tableName, ' TO ', newTableName);
SET @myQuery = t_query;
PREPARE stmt FROM @myQuery;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END LOOP;
END$$
区切り文字;
table_schema を実際の table_schema 名に置き換えます。