The mysql statement to delete data is "DELETE", which can delete one or more rows of data in the data table. The syntax format is "DELETE FROM
[WHERE clause] [ORDER BY clause] [LIMIT clause]".
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
In MySQL, you can use the DELETE statement to delete one or more rows of data in a table.
DELETE statement can delete data from a single table. The syntax format is:
DELETE FROM <表名> [WHERE 子句] [ORDER BY 子句] [LIMIT 子句]Copy after loginThe syntax description is as follows:
- ##
: Specify the table name from which data is to be deleted.
- 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.Usage example of DELETE statement
Delete all data in the table
[Example 1] Delete all data in the tb_courses_new tablemysql> DELETE FROM tb_courses_new; Query OK, 3 rows affected (0.12 sec) mysql> SELECT * FROM tb_courses_new; Empty set (0.00 sec)Copy after loginDelete data in the table based on conditions
[Example 2] In the tb_courses_new table, delete the course_id as 4 The recordIt can be seen from the running results that the record with course_id 4 has been deleted. [Related recommendations: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)Copy after loginmysql video tutorial]
The above is the detailed content of What is the mysql statement to delete data?. For more information, please follow other related articles on the PHP Chinese website!
Related labels:source:php.cnPrevious article:What is the difference between oracle and mysql Next article:What are the comment characters of mysql?Statement of this WebsiteThe 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.cnLatest Articles by Author
2023-04-26 17:59:18 2023-04-26 17:47:48 2023-04-26 17:41:42 2023-04-26 17:37:05 2023-04-26 17:31:25 2023-04-26 17:27:32 2023-04-25 19:57:58 2023-04-25 19:53:11 2023-04-25 19:49:11 2023-04-25 19:41:54Latest IssuesRegular expression to match words I have a script where I am trying to match new job names with existing job names in a data...From 2024-04-06 21:24:0401606How to group and count in MySQL? I'm trying to write a query that extracts the total number of undeleted messages sent to f...From 2024-04-06 18:30:1701353MySQL gets data from multiple tables I have a eg_design table which contains the following columns: and eg_domains table which ...From 2024-04-06 18:42:4402479Related TopicsMore>