Sql - Delete records in bulk - Delete in bulk

4

I have a table with about 4 million records.

What is the best method to delete all of them to get the best time? Does Indexing help anything, since it is just a reference for finding data?

OBS

'DELETE FROM tb_name;' // Demorou em torno de 45min
    
asked by anonymous 09.10.2015 / 15:39

2 answers

6

Truncate has better performance than a delete with no where because the first does not log the deleted lines while the second does this for each one.

TRUNCATE table nome can be translated by the bank as, I deleted the records, truncate is DML.

DELETE FROM nome , is translated as, I did log 1 log, I deleted log 1 ... Until N. delete is a DML

    
09.10.2015 / 15:44
6

Use TRUNCATE to delete all records.

TRUNCATE table;

This is an optimized method for complete deletion of records. If you want to propagate the effect to tables that refer to a primary key in the TRUNCATE table, use the parameter CASCADE ;

TRUNCATE table CASCADE;

Source:

link

    
09.10.2015 / 15:44