[WHERE clause] [ORDER BY clause] [LIMIT clause]"; if the WHERE clause is not used, it is deleted. When you operate a qualified deletion condition, all data will be deleted."/> [WHERE clause] [ORDER BY clause] [LIMIT clause]"; if the WHERE clause is not used, it is deleted. When you operate a qualified deletion condition, all data will be deleted.">
The database delete statement delete is used to delete one or more rows of data in a table. The syntax format is "DELETE FROM ccc43248daffbac9770dee47fdaff697 [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 子句]
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 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)
Example 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)
It 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!