How to delete row data in a data table by mysql
Editor to share with you how mysql deletes the row data in the data table, I believe most people do not know much about it, so share this article for your reference. I hope you will gain a lot after reading this article. Let's learn about it together.
In mysql, you can use the delete statement to delete one or more rows of data from a data table, with the syntax "DELETE FROM [WHERE clause] [ORDER BY clause] [LIMIT clause]"; when the WHERE condition is not used, all data is deleted.
In MySQL, you can use the DELETE statement to delete one or more rows of data from a table.
Delete data from a single table
Use the DELETE statement to delete data from a single table in the syntax format:
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.
Note: when the WHERE condition is not used, all data will be deleted.
Delete all data in the table
[example 1] Delete all the data in the tb_courses_new table, and the input SQL statement and the execution result are shown below.
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 the data in the table according to the condition
[example 2] in the tb_courses_new table, delete the record with course_id 4, and enter the SQL statement and the execution result as shown below.
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 can be seen from the running results, the record with a course_id of 4 has been deleted.
The above is how mysql deletes all the contents of the rows in the data table. 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!