码迷,mamicode.com
首页 > 数据库 > 详细

mysql 删除批量删除表

时间:2018-04-30 19:51:39      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:order   exec   UNC   des   def   varchar   sql   rem   auto   

BEGIN
declare done int default false;
declare table_name_str VARCHAR(64);
declare table_rows_mum int;
DECLARE sqltext VARCHAR(2000); # 拼接sql串
DECLARE auto_sql_str VARCHAR(2000);

declare _Cur cursor for select table_name,table_rows from information_schema.`TABLES` where TABLE_SCHEMA = ‘tzgame‘ and table_rows = 0 order by table_rows desc ;#主订单查询
declare continue HANDLER for not found set done = true;
OPEN _Cur;
FETCH _Cur INTO table_name_str,table_rows_mum;
while(not done) do
set sqltext:= CONCAT(‘TRUNCATE ‘, table_name_str,‘;‘);
set auto_sql_str:= CONCAT(‘ ALTER TABLE ‘, table_name_str, ‘ AUTO_INCREMENT = 1; ‘);

PREPARE STMT FROM sqltext;
EXECUTE STMT;

PREPARE STMT FROM auto_sql_str;
EXECUTE STMT;

fetch _Cur into table_name_str,table_rows_mum;
end while;
CLOSE _Cur;
end

mysql 删除批量删除表

标签:order   exec   UNC   des   def   varchar   sql   rem   auto   

原文地址:https://www.cnblogs.com/chenkg/p/8974115.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!