Three ways to delete data in Oracle

Three ways to delete data in Oracle

Statements to delete tables (records and structures) delete——truncate——drop

drop command

drop table table name;

For example: delete student table (student)
drop table student;

Note:
        1. Using drop to delete table data will not only delete the data in the table, but also delete the structure!

truncate command

truncate table   table name;

For example: delete student table (student)
truncate table student;

Note:
        1. Using truncate to delete table data only deletes the data in the table, the table structure will not be deleted!
        2. When deleting the data of the entire table, the process is that the system deletes the data at once, which is more efficient.
        3. Truncate deletion to free up space.

delete command

delete from  table name;

For example: delete student table (student)
delete from  student;

Note:       
        1. Using delete to delete table data only deletes the data in the table, the table structure will not be deleted!
        2. Although the data of the entire table is also deleted, the process is that the system deletes rows one by one, which is less efficient than truncate
        . 3. Delete does not release space.

A brief summary about truncate:

truncate table is functionally identical to the delete statement without a where clause: both delete all rows in the table.

However, truncate is faster than delete and uses less system and transaction log resources.

The delete statement deletes one row at a time and records an entry in the transaction log for each row deleted. Therefore, the delete operation can be rolled back.

1. Truncate is very fast on various tables, whether large or small. If there is a rollback command, delte will be revoked, but truncate will not be revoked.

2. Truncate is a DDL language. Like all other DDL languages, it will be implicitly submitted and the rollback command cannot be used on truncate.

3. Truncate will reset the high level and all indexes. When fully browsing the entire table and indexes, the table after the truncate operation is much faster than the table after the delete operation.

4. Truncate cannot trigger any delete trigger.

5. When the table is cleared, the table and the indexes of the table will be reset to the initial size, but delete will not.

6. The parent table cannot be cleared

Guess you like

Origin blog.csdn.net/weixin_44657888/article/details/122313659