MySQL_Shell_清空数据库表中的数据

来源:互联网 发布:mysql的好处 编辑:程序博客网 时间:2024/04/30 11:28


今天博主写了一个删除数据库数据的存储过程,如下所示:


drop procedure if exists del_all_tb;delimiter $$create procedure del_all_tb(db char(20))begin    declare done int default 0;    declare tb char(100);    declare cur cursor for select table_name from infoRmation_schema.tables where table_schema = db;    declare continue handler for not found set done = 1;    open cur;         repeat        fetch cur into tb;        set @sql := concat("truncate ", tb, ";");        prepare stmt from @sql;        execute stmt;        deallocate prepare stmt;     until done end repeat;    close cur;end $$delimiter ;call del_all_tb("数据库名");drop procedure if exists del_all_tb;




0 0