Home >Database >Mysql Tutorial >How to clear data table data in mysql
In mysql, you can use the "DELETE" and "TRUNCATE" keywords to clear the data in the data table. The specific syntax is "DELETE FROM data table;" and "TRUNCATE TABLE data table;".
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
MySQL provides the DELETE and TRUNCATE keywords to delete data in the table.
MySQL DELETE keyword
In MySQL, you can use the DELETE statement to delete one or more rows of data in a table.
Use the DELETE statement to delete data from a single table. The syntax format is:
DELETE FROM <表名> [WHERE 子句] [ORDER BY 子句] [LIMIT 子句]
The syntax description is as follows:
Delete all data in the table
Example: Delete all data in the tb_courses tablemysql> DELETE FROM tb_courses; Query OK, 3 rows affected (0.12 sec) mysql> SELECT * FROM tb_courses; Empty set (0.00 sec)
MySQL TRUNCATE keyword
The TRUNCATE keyword is used to completely clear a table. The syntax format is as follows:TRUNCATE [TABLE] 表名Among them, the TABLE keyword can be omitted. Example: Use the TRUNCATE statement to clear the records in the tb_student_course table
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)(Recommended tutorial:
mysql video tutorial)
The difference between TRUNCATE and DELETE
Logically speaking, the TRUNCATE statement has the same effect as the DELETE statement, but in some cases, there are differences in their use.Introduction to Programming! !
The above is the detailed content of How to clear data table data in mysql. For more information, please follow other related articles on the PHP Chinese website!