Home  >  Article  >  Database  >  How to delete all data in the data table in mysql?

How to delete all data in the data table in mysql?

青灯夜游
青灯夜游Original
2020-10-15 11:54:3520613browse

Mysql method of deleting all data in a data table: Use the DELETE statement of SQL to delete all data. The syntax format is "DELETE FROM data table name;"; you can also set the "WHERE" subtitle in the DELETE statement. Sentence to define the deletion conditions for the deletion operation and delete the specified records in the data table.

How to delete all data in the data table in mysql?

(Recommended tutorial: mysql video tutorial)

In MySQL, you can use the DELETE statement to delete a table One or more rows of data.

Syntax

The following is the general syntax of the SQL DELETE statement to delete data from the MySQL data table:

DELETE FROM 数据表名 [WHERE 子句] [ORDER BY 子句] [LIMIT 子句]

The syntax is explained as follows:

  • Data table name: Specify the name of the table to delete data.

  • WHERE clause: Optional. Indicates that the deletion condition is qualified for the deletion operation. You can specify any condition in the WHERE clause. If no WHERE clause is specified, all records in the MySQL table will be deleted.

  • ORDER BY clause: Optional. Indicates that when deleting, rows in the table will be deleted in the order specified in the clause.

  • LIMIT clause: Optional. Used to tell the server the maximum number of rows to be deleted before the control command is returned to the client.

You can delete records in a single table at once; the WHERE clause is very useful when you want to delete specified records in the data table.

Note: When the WHERE condition is not used, all data will be deleted.

Example: Delete all data in the table

[Example 1] Delete all data in the tb_courses_new table. The input SQL statement and execution results are as follows Show.

mysql> DELETE FROM tb_courses_new;
Query OK, 3 rows affected (0.12 sec)

mysql> SELECT * FROM tb_courses_new;
Empty set (0.00 sec)

The above is the detailed content of How to delete all data in the data table in mysql?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn