Get the App
SLTechnology News&Howtos  ›  Database  › 

What is the function of the database delete statement delete

Shulou Source: shulou.com Published: 2022-06-01 02:15:51 09月14日 Update

Editor to share with you what the role of database deletion statement delete is, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The database delete statement delete is used to delete one or more rows of data from a table in the syntax format "DELETE FROM [WHERE clause] [ORDER BY clause] [LIMIT clause]"; when you do not use the WHERE clause to qualify the deletion operation, all data will be deleted.

Delete statement delete

The DELETE statement can delete one or more rows of data from a table.

The syntax format is:

DELETE FROM [WHERE clause] [ORDER BY clause] [LIMIT clause]

The syntax is as follows:

Specifies the name of the table to delete the data

ORDER BY clause: optional. When you delete, the rows in the table are deleted in the order specified in the clause.

WHERE clause: optional. Indicates that the deletion condition is qualified for the delete operation, and if the clause is omitted, all rows in the table are deleted.

LIMIT clause: optional. Used to tell the server the maximum value of the deleted row 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 a table according to 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 | 2015 | 09-10 | 2 | Green | 3 | 23 | F | 2016-10-22 | 3 | Henry | 2 | 23 | M | 2015-05-31 | 5 | Jim | 1 | 24 | M | 2016-01-15 | 6 | John | | 2 | 21 | M | 2015 | 11-11 | | 7 | Lily | 6 | 22 | F | 2016-02-26 | 8 | Susan | 4 | 23 | F | 170 | 2015-10-01 | +-+-- -+ 4 rows in set (0.00 sec)

As can be seen from the running results, the record with an id of 4 has been deleted.

The above is the database delete statement delete what is the role of all the content, thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Clause data statement database condition syntax function one line content format example article multiple lines maximum less middle finger representative command most customer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn macOS Microsoft Shulou Technology MariaDB