Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    re-write sql to reverse

    I found a SQL query online that I am using to rename all the tables within a data base...

    Code:
    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.

    Code:
    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.

  • #2
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry for asking, just had to keep tweaking it

    Code:
    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";


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •