Skip to content

Instantly share code, notes, and snippets.

@66Ton99
Last active October 10, 2015 15:58
Show Gist options
  • Save 66Ton99/3715102 to your computer and use it in GitHub Desktop.
Save 66Ton99/3715102 to your computer and use it in GitHub Desktop.
Deletes all tables in current DB
delimiter $$
create procedure drop_tables_like(pattern varchar(255), db varchar(255))
begin
select @str_tables:=group_concat(table_name)
from information_schema.tables
where table_schema=db and table_name like pattern;
IF @str_tables IS NOT NULL THEN
SET @str_sql := concat('drop table ', @str_tables);
prepare stmt from @str_sql;
execute stmt;
drop prepare stmt;
END IF;
end$$
call drop_tables_like('%%', DATABASE())$$
drop procedure drop_tables_like$$
delimiter ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment