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
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?
'DELETE FROM tb_name;' // Demorou em torno de 45min
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
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: