How does MySql delete multiple tables in batches

Project scenario:

使用Navicat工具直接在界面中删除,只能单张表删除,不能多选。


solution:

We can delete multiple tables in batches through MySQL statements, where test is replaced with the name of the database you want to query.

1. Generate SQL to delete all tables under a certain database

-- 查询构建批量删除表语句(根据数据库名称)
select concat('drop table ', TABLE_NAME, ';') from information_schema.TABLES
where TABLE_SCHEMA = 'test';

2. Generate SQL to delete the specified table name under a certain database

-- 查询构建批量删除表语句(根据数据库中的表名称模糊查询)
select concat('drop table ', TABLE_NAME, ';') from information_schema.TABLES
where TABLE_SCHEMA = 'test' and TABLE_NAME like 'sys_%';

Copy the detected delete SQL statements and execute them in batches.

drop table sys_dept;
drop table sys_dict;
drop table sys_log;
drop table sys_log_2022;
drop table sys_menu;
drop table sys_notice;
drop table sys_role;
drop table sys_role_menu;
drop table sys_user;
drop table sys_user_dept;
drop table sys_user_role;
drop table sys_user_token;

 

Guess you like

Origin blog.csdn.net/u011974797/article/details/129811283