mysql delete table data (drop, truncate and delete)

There are two ways to delete data in MySQL, one is the DELETE statement and the other is the TRUNCATE TABLE statement. The DELETE statement can select the records to be deleted through WHERE. Whereas using TRUNCATE TABLE will delete all records in the table.
1. drop table tb
drop directly deletes the table, and there is no way to retrieve it
. 2. truncate (table) tb
deletes all data in the table, and cannot be used with
where
. where delete certain rows)

Difference: the difference between truncate and delete
1. Transaction: After truncate is deleted, the mysql log is not recorded, the data cannot be recovered, and it cannot be rolled back. truncate is equivalent to retaining the structure of the mysql table and re-creating the table, and all the states are equivalent on the new table. The effect of delete is a bit like deleting all records in the mysql table one by one until the deletion is complete, and delete can be rolledback;
reason: truncate deletes the entire table data (ddl statement, implicit submission), delete is a row-by-row deletion, which can be rolledback
2 , Effect: In efficiency, truncate is faster than delete. After truncate is deleted, the index will be rebuilt (id starts from zero). Delete will not delete
the index. 3. Truncate cannot trigger any Delete trigger.
4. DELETE can return the number of records deleted, while TRUNCATE TABLE returns 0

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325648712&siteId=291194637