Leif160519的blog Leif160519的blog

——————

目录
MySQL批量表操作
/  

MySQL批量表操作

批量删除指定前缀的表

select CONCAT( 'drop table ', table_name, ';' )  
from information_schema.tables  
where table_name like 'dede_%';

"dede"为要删除的表前缀,执行此SQL语句后会生成一串SQL语句,必须再执行生成的这些SQL语句才能真正执行删除操作

image.png

批量修改表名

Select CONCAT( 'alter table ', table_name, 'rename to ', table_name,';' ) 
from information_schema.tables 
where table_name like 'dede_%';

首先执行此SQL语句,会生成如下语句:

alter table de_aaa rename to de_aaa; 
alter table de_bbb rename to de_bbb;

在编辑器中将rename to de批量改为想设置的表前缀,再执行此SQL语句即可批量修改表名。

原文引用:https://www.cnblogs.com/haocool/archive/2013/06/25/3153984.html


“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” – Tom Cargill

标  题MySQL批量表操作
作  者Leif160519
出  处https://github.icu/articles/2019/09/23/1569225654377.html
关于博主:坐标南京,运维工程师,如有问题探讨可以直接下方留言。
声援博主:如果您觉得文章对您有帮助,可以评论、订阅、收藏。您的鼓励是博主的最大动力!