...

View Full Version : re-write sql to reverse



bowers
03-26-2013, 09:16 PM
I found a SQL query online that I am using to rename all the tables within a data base...


SELECT GROUP_CONCAT('RENAME TABLE `', TABLE_SCHEMA, '`.`', TABLE_NAME, '` TO `', TABLE_SCHEMA, '`.`delete_me_', TABLE_NAME, '`;' SEPARATOR ' ') as full_description FROM information_schema.TABLES WHERE `TABLE_SCHEMA` = "database";


Can you please help me edit the script to reverse this process. So in this case remove the "delete_me_" from all of the edited table names.

I thought using a sub string would work but I cant get the syntax to mesh.


SELECT GROUP_CONCAT('RENAME TABLE `', TABLE_SCHEMA, '`.`', TABLE_NAME, '` TO `', TABLE_SCHEMA, '`.`'SUBSTRING(table_name,4,5) '`;' SEPARATOR ' ') as full_description FROM information_schema.TABLES WHERE `TABLE_SCHEMA` = "analytics_2";



thanks in advance.

bowers
03-26-2013, 10:56 PM
sorry for asking, just had to keep tweaking it


SELECT GROUP_CONCAT('RENAME TABLE `', TABLE_SCHEMA, '`.`', TABLE_NAME, '` TO `', TABLE_SCHEMA, '`.`',substring(TABLE_NAME,11,25),'`;' SEPARATOR ' ') FROM information_schema.TABLES WHERE `TABLE_SCHEMA` = "analytics_2";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum