0

I have above 60M rows to delete from 2 separate tables (38M and 19M). I have never deleted this amount of rows before and I'm aware that it'll cause things like rollback errors etc. and probably won't complete.

What's the best way to delete this amount of rows?

3
  • 1
    how many rows will be left in each table? Commented Dec 2, 2013 at 9:04
  • see here if this can be applied Commented Dec 2, 2013 at 9:06
  • @DavidAldridge First table is 44M rows and 38M to be deleted. Second table is 22M rows and 19M to be deleted. Commented Dec 2, 2013 at 9:07

1 Answer 1

1

You can delete some number of rows at a time and do it repeatedly.

delete from *your_table*
where *conditions*
  and rownum <= 1000000

The above sql statement will remove 1M rows at once, and you can execute it 38 times, either by hand or using PL/SQL block.

The other way I can think of is ... If the large portion of data should be removed, you can negate the condition and insert the data (that should be remained) to a new table, and after inserting, drop the original table and rename the new table.

create table *new_table* as
select * from *your_table*
where *conditions_of_remaining_data*

After the above, you can drop the old table, and rename the table.

drop table *your_table*;
alter table *new_table* rename to *your_table*;
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. I think first I'll give the first suggestion a shot and see how that works out. Would doing such a large deletion noticeably slow down the system? I guess that depends on the system?
Dont drop the old table, as you will have to create all triggers, indices etc from scratch. Just truncate the old table and insert the retained records... all described in the link given on the original question
@user2656114 Well, if you decided to use delete, be sure to avoid the full table scan.
@ntalbs Can you explain or provide an example of repeating it using using PL/SQL block please?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.