MySQL 清空表的内容

(1)delete form 表名,清空表的内容

mysql> use test;
Database changed
mysql> create table teacher(age int(3));
Query OK, 0 rows affected (0.07 sec)

mysql> insert into teacher values(111), (45), (23), (34);
Query OK, 4 rows affected (0.04 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> select * from teacher;
+------+
| age  |
+------+
|  111 |
|   45 |
|   23 |
|   34 |
+------+
4 rows in set (0.00 sec)

mysql> delete from teacher;
Query OK, 4 rows affected (0.03 sec)

mysql> select * from teacher;
Empty set (0.00 sec)

mysql>

(2)truncate 表名,清空表的内容

mysql> use test;
Database changed
mysql> create table teacher(age int(3));
Query OK, 0 rows affected (0.05 sec)

mysql> insert into teacher values(111), (45), (23), (34);
Query OK, 4 rows affected (0.03 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> select * from teacher;
+------+
| age  |
+------+
|  111 |
|   45 |
|   23 |
|   34 |
+------+
4 rows in set (0.00 sec)

mysql> truncate teacher;
Query OK, 0 rows affected (0.11 sec)

mysql> select * from teacher;
Empty set (0.00 sec)

mysql>
原文地址:https://www.cnblogs.com/Robotke1/p/3054958.html