Oracle quick batch data deletion

Source: Internet
Author: User

Requirements:

1. A customer table named Pers, whose primary key is the customer ID persnbr;

2. The seven columns in the pers table have foreign key constraints;

2. In the pers table, 0.1 million pieces of data are generated in batches (persnbr> = 100000000 pieces of data). Now you need to delete these 0.1 million pieces of data to facilitate re-generation.

Solution:

1. directly execute the delete from pers where persnbr> = 100000000, and the result is too slow.

2. Use the TRUNCATE Syntax:

Create table pers_TEMP as select * from pers where persnbr <100000000; -- back up the records smaller than 100000000, and the query statement will be faster

Truncate table pers; -- clears all data in pers, which is fast

Insert into pers select * from pers_TEMP; -- inserts the backup data into the pers table.

Comparison between truncate and delete

1. truncate is much faster than delete, and less system and transaction log resources are used. This is because truncate deletes data by releasing the data pages used to store table data, and only records the release of pages in transaction logs. The delete statement deletes a row each time, in the transaction log, each row is deleted.

2. truncate is a ddl statement and delete is a dml statement. Like other ddl statements, truncate will be implicitly committed, so you cannot use the rollback command for truncate. The deletion of each record in the delete statement will be recorded in the transaction log, so it can be rollback.

3. The truncate statement will reset the index value of the table to the initial size, but the delete statement cannot.

Use a Linux File handle to restore accidentally deleted Oracle data files

Several ways to delete duplicate records in Oracle

How to quickly delete duplicate data in Oracle

Comparison between Delete statements and Truncate statements for Oracle database data deletion

Oracle uses the delete command to delete data recovery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.