Its grammatical structure is:
The code is as follows |
Copy Code |
TRUNCATE [TABLE] Tbl_name |
Here's a simple example,
I want to delete all the records in the Friends table, you can use the following statement:
The code is as follows |
Copy Code |
TRUNCATE TABLE friends; |
The effect of the delete is a bit like deleting all the records in the MySQL table to the end, and truncate is equivalent to preserving the MySQL table structure, recreating the table, and all States are equivalent to the new table.
Grammar:
The definition of the DELETE statement.
The code is as follows |
Copy Code |
DELETE [low_priority] [QUICK] [IGNORE] from Tbl_name [WHERE Where_definition] [Order BY ...] [LIMIT Row_count] |
MySQL's syntax is similar to spoken language, you have to point out which table you want to delete data, and delete which data, this is enough. Just like when writing a narrative, time, place, character, environment and plot elements are essential.
The example is the most image and the most descriptive question. So, not the whole useless, directly into the subject. Following the syntax structure above, I want to delete all the user_name equals Simaopig records in the Firends table,
You can use the following SQL statement:
The code is as follows |
Copy Code |
Delete from friends where user_name = ' Simaopig ';d elete |
Note:
From the syntax structure, we can see that, like the update syntax, we can omit the WHERE clause. But this is a very dangerous behavior. Because if you do not specify a WHERE clause, delete deletes all the records in the table and deletes them immediately, even if you have no place to cry, and no time, because you need to immediately acknowledge the error with the supervisor, and immediately find the MySQL log and roll back the record. But once you have had such an experience, I believe it must be impressive.
The strange thing is that I am on the InnoDB and MyISAM on the large amount of data, the index file under great circumstances, it is almost impossible to delete the success! Left to settle.
Summarize
However, the truncate command is fast, but it is not as secure as the delete command for transaction processing. Therefore, if we want to perform a transaction on a table that truncate deletes, this command generates an exit and generates an error message.