[WHERE clause] [ORDER BY clause] [LIMIT clause]"; when the WHERE condition is not used time, all data will be deleted."/> [WHERE clause] [ORDER BY clause] [LIMIT clause]"; when the WHERE condition is not used time, all data will be deleted.">

Home  >  Article  >  Database  >  How to delete row data (records) in the data table in mysql?

How to delete row data (records) in the data table in mysql?

青灯夜游
青灯夜游Original
2020-10-02 12:12:3032452browse

In mysql, you can use the DELETE statement to delete one or more rows of data in the data table. The syntax "DELETE FROM ccc43248daffbac9770dee47fdaff697 [WHERE clause] [ORDER BY clause] [LIMIT clause] "; When the WHERE condition is not used, all data will be deleted.

How to delete row data (records) in the data table in mysql?

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

Delete data in a single 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:

  • 722e3d59fd24604761db25f00f9b264f: Specify the name of the table to delete data.

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

  • WHERE clause: Optional. Indicates that the deletion conditions are limited for the deletion operation. If this clause is omitted, it means that all rows in the table are deleted.

  • 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.

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

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.

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)

Delete data in the table based on conditions

[Example 2] In the tb_courses_new table, delete the record with course_id 4. The input SQL statement and execution results are as follows shown.

mysql> DELETE FROM tb_courses
    -> WHERE course_id=4;
Query OK, 1 row affected (0.00 sec)
mysql> SELECT * FROM tb_courses;
+-----------+-------------+--------------+------------------+
| course_id | course_name | course_grade | course_info      |
+-----------+-------------+--------------+------------------+
|         1 | Network     |            3 | Computer Network |
|         2 | Database    |            3 | MySQL            |
|         3 | Java        |            4 | Java EE          |
+-----------+-------------+--------------+------------------+
3 rows in set (0.00 sec)

It can be seen from the running results that the record with course_id 4 has been deleted.

Recommended tutorial: mysql video tutorial

The above is the detailed content of How to delete row data (records) 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