阅读量:9
drop table 表名;
如果有200张表,执行200次,想想就不想动手了。
下面提供一个使用information_schema库的方案:
SELECT CONCAT('drop table ',table_name,';') FROM information_schema.`TABLES` WHERE table_schema='数据库名';
例子
mysql> SELECT CONCAT('drop table ',table_name,';') FROM information_schema.`TABLES` WHERE table_schema='django_demo';
+----------------------------------------+
| CONCAT('drop table ',table_name,';') |
+----------------------------------------+
| drop table auth_group; |
| drop table auth_group_permissions; |
| drop table auth_permission; |
| drop table auth_user; |
| drop table auth_user_groups; |
| drop table auth_user_user_permissions; |
| drop table django_admin_log; |
| drop table django_content_type; |
| drop table django_migrations; |
| drop table django_session; |
| drop table tb_books; |
+----------------------------------------+
11 rows in set (0.00 sec)
去掉|
a = '''
| drop table auth_group; |
| drop table auth_group_permissions; |
| drop table auth_permission; |
| drop table auth_user; |
| drop table auth_user_groups; |
| drop table auth_user_user_permissions; |
| drop table django_admin_log; |
| drop table django_content_type; |
| drop table django_migrations; |
| drop table django_session; |
| drop table tb_books; '''
print(a.replace('|', ''))
复制到数据库执行两次(因为可能表有关联)