ITeye博客

批量删除数据库表

wode66 · 2011-07-26 13:34 · mysql · 数据库 · Markdown

mysql中批量删除以某个前缀开头的表,没有现成的sql,只能写存储过程,定义如下:

delimiter $$
create procedure drop_tables_like(pattern varchar(255), db varchar(255))
begin
select @str_sql:=concat('drop table ', group_concat(table_name))
from information_schema.tables
where table_schema=db and table_name like pattern;

prepare stmt from @str_sql;
execute stmt;
drop prepare stmt;
end$$

 执行:

call drop_tables_like('kw_%', 'db_1')$$

 删除存储过程:

drop procedure if exists drop_tables_like$$
delimiter ;

 

 

参考文章:

  http://dev.mysql.com/doc/refman/5.0/en/drop-table.html

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。