The database delete statement delete is used to delete one or more rows of data in a table. The syntax format is "DELETE FROM
[WHERE clause] [ORDER BY clause] [LIMIT clause]"; When you do not use the WHERE clause to define the deletion conditions for the deletion operation, all data will be deleted.
(Recommended tutorial: mysql video tutorial)
Delete statement delete
The DELETE statement can delete one or more rows of data in the table.
The syntax format is:
DELETE FROM <表名> [WHERE 子句] [ORDER BY 子句] [LIMIT 子句]Copy after loginThe syntax description is as follows:
: 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 deleting all rows in the table.
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.
Example 1: Delete all data in the table
Delete all data in the tb_courses table
mysql> DELETE FROM tb_students; Query OK, 3 rows affected (0.12 sec) mysql> SELECT * FROM tb_students; Empty set (0.00 sec)Copy after loginExample 2: Delete data in the table based on conditions
In the tb_students table, delete the record with id 4
mysql> DELETE FROM tb_students -> WHERE id=4; Query OK, 1 row affected (0.00 sec) mysql> SELECT * FROM tb_students; +----+-------+---------+------+------+--------+------------+ | id | name | dept_id | age | sex | height | login_date | +----+-------+---------+------+------+--------+------------+ | 1 | Dany | 1 | 25 | F | 160 | 2015-09-10 | | 2 | Green | 3 | 23 | F | 158 | 2016-10-22 | | 3 | Henry | 2 | 23 | M | 185 | 2015-05-31 | | 5 | Jim | 1 | 24 | M | 175 | 2016-01-15 | | 6 | John | 2 | 21 | M | 172 | 2015-11-11 | | 7 | Lily | 6 | 22 | F | 165 | 2016-02-26 | | 8 | Susan | 4 | 23 | F | 170 | 2015-10-01 | +----+-------+---------+------+------+--------+------------+ 4 rows in set (0.00 sec)Copy after loginIt can be seen from the running results that the record with id 4 has been been deleted.
The above is the detailed content of What is the use of the database delete statement delete?. For more information, please follow other related articles on the PHP Chinese website!
Previous article:What are the database isolation levels? Next article:How to remove a string in mysqlStatement 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:0401606MySQL 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:4402479Group MySQL results by ID for looping over I have a table with flight data in mysql. I'm writing a php code that will group and displ...From 2024-04-06 17:27:5601406Related TopicsMore>