mysql批量删除空表_mysql 删除批量删除表

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值