Mysql 批量删除数据表数据
drop:不再需要该表;
truncate:保留该表,但要删除所有记录;
delete:要删除部分记录或者有可能会后悔的话, 用 delete;
1. drop table tb;
drop 是直接将表格删除,无法找回。例如删除 user 表:
drop table user;
2. truncate (table) tb;
truncate 是删除表中所有数据,但不能与where一起使用;
TRUNCATE TABLE user;
3. delete from tb (where);
delete 也是删除表中数据,但可以与where连用,删除特定行;
-- 删除表中所有数据
delete from user;
-- 删除指定行
delete from user where username ='Tom';
批量操作:
1、执行如下语句获取删除语句
drop:
SELECT CONCAT('drop table ',table_name,';') FROM information_schema.`TABLES` WHERE table_schema='数据库名';
truncate:
SELECT CONCAT('TRUNCATE table ',table_name,';') FROM information_schema.`TABLES` WHERE table_schema='数据库名';
delete:
SELECT CONCAT('delete from ',table_name,';') FROM information_schema.`TABLES` WHERE table_schema='数据库名';
2、拷贝语句,然后执行
因篇幅问题不能全部显示,请点此查看更多更全内容