MySQL method to delete all tables in the database:
-- switch to the database where you want to delete the table use replace_with_database_name_you_want_to_delete;-- Delete all tables Set foreign_key_ checks = 0; set group_concat_max_len=32768; set @tables = NULL; Select group_concat (", table_name, ") INTO @tables FROM information_schema.tables where table_schema = (Select database ()); Select ifnull (@tables, ' dummy ') INTO @tables; set @tables = concat (' drop table if exists ', @tables); prepare stmt from @tables; execute stmt;deallocate prepare stmt; set foreign_key_checks = 1;-- Delete all views set foreign_key_checks = 0; set group_concat_max_len=32768; set @views = NULL; Select group_concat (", table_name, ") INTO @views FROM information_schema.views where table_schema = (Select datAbase ()); Select ifnull (@views, ' dummy ') INTO @views; set @views = concat (' drop view if exists ', @views); prepare stmt from @views; execute stmt;deallocate prepare stmt; set foreign_key_checks = 1;
This article is from the "GONE with the Wind" blog, please be sure to keep this source http://h2appy.blog.51cto.com/609721/1676871
Methods for all tables in MySQL