Mysql add, delete, modify, delete records

Use delete to delete records

Category Detailed explanation
Basic syntax DELETE FROM table [where condition];
Example DELETE FROM user where id > 10;
Example description Delete all users with ID greater than 10 in the user table

user table, the table structure is as follows:

##16 Chen He 1234131.00
id username balance
1 王宝强 50000.00
2 黄晓明 150000000.00
15 马云 15000.00
mysql> DELETE FROM user where id = 1;

Query OK, 1 row affected (0.08 sec)

Delete the record of the row with ID 1, Li Wenkai.

Clear table records

delete and truncate are the same, but they have one difference, that is, DELETE can return the number of deleted records, while TRUNCATE TABLE returns 0.

If there is an auto-increment field in a table, use truncate table. This auto-increment field will restore the starting value to 1.

Category Description Basic syntax TRUNCATE TABLE table name; Example TRUNCATE TABLE user; Example description Clear the table data and let the auto-incremented id start from 1

【Remember】

    Be sure to remember to add the where condition when deleting, otherwise the records in the entire table will be cleared.
  1. Be sure to back up, back up, back up before deleting important data.
Continuing Learning
||
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!