我有一个表的mySQL数据库,类似于:
users
tests
billing我正在寻找一个SQL查询,它循环遍历数据库中的表,并将application_附加到名称,结果是:
application_users
application_tests
application_billing发布于 2013-08-16 18:58:48
根据您使用的操作系统,您是否考虑过编写一个shell脚本来通过sed管道"show tables“命令的输出,以生成包含适当alter table命令的脚本文件?
amrith@amrith-vbox:~/so$ more showtables.sql
show tables
amrith@amrith-vbox:~/so$ mysql -uroot -ppassword -N test < showtables.sql | awk '{ print "alter table " $1 " rename to abc_"$1 }'
alter table conversations rename to abc_conversations
alter table foo rename to abc_foo
alter table messages rename to abc_messages
alter table t1 rename to abc_t1
amrith@amrith-vbox:~/so$您可以将输出发送到某个.sql文件,然后使用mysql执行它?
发布于 2013-08-16 17:07:52
RENAME TABLE
`database`.`table_1234` TO `database`.`new_table_1234`,
`database`.`table_3456` TO `database`.`new_table_3456`; https://stackoverflow.com/questions/18269617
复制相似问题