Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to delete data in mysql

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly shows you "how to delete data in mysql". The content is simple and easy to understand and the organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn this article "how to delete data in mysql".

The mysql statement for deleting data is "Delete," which deletes one or more rows of data from a data table in the syntax format "Delete FROM [WHERE clause] [ORDER BY clause] [LIMIT clause]."

Operating environment of this tutorial: Windows 7 system, MySQL8 version, Dell G3 computer.

In MySQL, you can delete one or more rows of data from a table by using the Delete statement.

Delete statement deletes data from a single table. Syntax:

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

The syntax is explained as follows:

: Specifies the name of the table from which data is to be deleted.

ORDER BY clause: optional. Indicates that when deleted, rows in the table are deleted in the order specified in the clause.

WHERE clause: optional. Indicates that the delete operation limits the delete condition. If this clause is omitted, it represents deleting all rows in the table.

LIMIT clause: Optional. Used to tell the server the maximum number of rows to delete before a control command is returned to the client.

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

Examples of the use of Delete statements

Delete all data from a table

[Example 1] Delete all data in tb_courses_new table

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 from tables based on conditions

Example 2: Delete the record with course_id = 4 in tb_courses_new table.

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)

As you can see from the results, the record with course_id 4 has been deleted.

The above is "how to delete data in mysql" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report