SQL的自动生成delete语句

时间:2022-09-06 17:35:47

当要清除数据库中表的数据时,自己写sql不好检查错误,也很麻烦。

可以使用下列语句自动生成语句,同时防止误操作,mysql 用 information_schema来存储数据库所有的信息

SELECT CONCAT('delete from ',table_name) FROM information_schema.tables WHERE table_schema='数据库名' AND table_type='base table';

效果

SQL的自动生成delete语句