mysql 存储过程批量删除表

 使用存储过程批量删除表

delimiter //
create procedure dro01()
begin
declare i int;
set i=21;
while i<41 do
 set @dro_1=concat('drop table ','t',i,';');
 select @dro_1;
  prepare tmt from @dro_1;
  EXECUTE tmt;
  deallocate prepare tmt;
 set i=i+1;
end while;
end;//

delimiter ;

 

也可以使用函数CONCAT来生成批量执行sql语句,再执行批量sql语句。 

批量删除特征表

SELECT CONCAT( 'drop table ', table_name, ';' ) 
FROM information_schema.tables 
WHERE TABLE_SCHEMA = 'db_name' table_name LIKE 'test_%';

批量删除存储过程

SELECT CONCAT( 'drop table ', ROUTINE_NAME, ';' ) FROM information_schema.`ROUTINES`
WHERE ROUTINE_SCHEMA='db_name';

 



posted @ 2019-01-16 18:01  Knight灬麒  阅读(2130)  评论(0编辑  收藏  举报