What is the difference between TRUNCATE TABLE and DELETE when deleting all records in the entire table

1.DELETE
 ・DML language
 ・Can go back
 ・Conditional deletion is possible

     DELETE FROM 表名
   WHERE condition

2.TRUNCATE TABLE
 ・DDL language
 ・Cannot go back
 ・By default all table contents are deleted
 ・Deletion is faster than delete.

   TRUNCATE TABLE table name



1. TRUNCATE is very fast on various tables, both large and small. If there is a ROLLBACK command Delete will be revoked,
TRUNCATE will not be revoked.
2. TRUNCATE is a DDL language. Like all other DDL languages, it will be implicitly submitted.
The ROLLBACK command cannot be used with TRUNCATE.
3. TRUNCATE will reset the high level line and all indexes. During a full browse of the entire table and index,
The table after TRUNCATE operation is much faster than the table after delete operation.
4. TRUNCATE cannot trigger any Delete trigger.
5. When the table is emptied, the table and the index of the table are reset to the initial size, but delete cannot.
6. The parent table cannot be emptied.

In oracle, after using delete to delete data, the storage capacity of the database will not be reduced, and use delete to delete the data of a table
In the future, the speed of querying this table will be the same as before deleting, and will not change.

Because oralce has a HWM high water mark, it is the highest water mark of the space used by a table in Oracle. When data is inserted, the high water mark
will rise, but if you delete the data with the delete statement , although the data is deleted, the high water mark has not decreased.
Or the water level that was as high as before you just deleted the data. Unless truncate is used to delete data. Then, this high water mark increases in daily
The deletion operation will only increase, not decrease, so the database capacity will only increase, not decrease. When using the select statement to query data,
The database will scan the data blocks below the high water mark. Because the high water mark has not changed, the scanning time will not be reduced, so the data will be displayed.
Now after using delete to delete data, the query speed is still the same as before delete.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326563586&siteId=291194637