TRUNCATE [TABLE] 表名
其中,TABLE 关键字可省略。mysql> CREATE TABLE `tb_student_course` ( -> `id` int(4) NOT NULL AUTO_INCREMENT, -> `name` varchar(25) NOT NULL, -> PRIMARY KEY (`id`) -> ); Query OK, 0 rows affected (0.04 sec) mysql> INSERT INTO tb_student_course(name) VALUES ('Java'),('MySQL'),('Python'); Query OK, 3 rows affected (0.05 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> SELECT * FROM tb_student_course; +----+--------+ | id | name | +----+--------+ | 1 | Java | | 2 | MySQL | | 3 | Python | +----+--------+ 3 rows in set (0.00 sec)使用 TRUNCATE 语句清空 tb_student_course 表中的记录,SQL 语句和运行结果如下:
mysql> TRUNCATE TABLE tb_student_course; Query OK, 0 rows affected (0.04 sec) mysql> SELECT * FROM tb_student_course; Empty set (0.00 sec)
Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有