日期:2014-05-16 浏览次数:20372 次
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??