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:
##16Chen He1234131.00id | username | balance |
---|---|---|
1 | 王宝强 | 50000.00 |
2 | 黄晓明 | 150000000.00 |
15 | 马云 | 15000.00 |
mysql> DELETE FROM user where id = 1;Delete the record of the row with ID 1, Li Wenkai. Clear table recordsdelete 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.CategoryDescriptionBasic syntaxTRUNCATE TABLE table name;ExampleTRUNCATE TABLE user;Example descriptionClear the table data and let the auto-incremented id start from 1Query OK, 1 row affected (0.08 sec)