Search code examples
mysqldatabasealter-table

How to remove a prefix name from every table name in specific MySQL database


All tables in specific MySQL database, for example my_db, start with a prefix which its length is 17 character. I want to remove prefix from name of all tables. How I can do this?


Solution

  • improved hasanghaforian's answer... removed extra concat functions.. still produces same output

    select concat('RENAME TABLE ', table_name, ' TO ' , substr(table_name,18) , ' ; ' ) from information_schema.tables where table_schema = 'my_db';