清空数据库表或数据

日常开发或服务器部署时,我们可能会遇到需要清空表或表数据的情况,下面语法执行结果即为清除语句,将结果复制到查询中执行即可。

table_schema='数据库名';

1、清空test库中表数据:

select concat('truncate table ',table_schema,'.',table_name,';') as '执行sql' from information_schema.TABLES where table_schema='test';

2、删除test库中所有表:

select concat('drop table ',table_schema,'.',table_name,';') as '执行sql' from information_schema.TABLES where table_schema='test';
原文地址:https://www.cnblogs.com/nvsky/p/11083982.html