We need to delete 50,000,000 change log entries via sql. How long would you expect this to take and is there anything i should consider before doing this?
The entries were created in error and aren't needed.
If you are about to clear all the table entirely use TRUNCATE, not DELETE. If you want to leave some of the records then do not delete remaining 50mil all in one go, all in one transaction, as this will likely lead to transaction log expansion, which is very costly and time-consuming operation. Delete them in batches 10k-100k records at a time instead, using
DELETE TOP (nnnnnn) FROM...; GO nnnn
(GO nnnn is the SSMS directive/command hence works from SSMS only)
Alternatively, select rows which are supposed to remain into a temp table, then truncate the change log entry table, and then copy back required data.
Truncate would be the best. If you can't use it, best first disable secondary keys and then delete the records (How:see other posts) and then re-enable the secondary keys again.
Regards,Alain Krikilion No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
I also did Truncate long back but it took way more time I remember as there were around 5 crore data. Try truncating post business hours and leave then!!
Answers
So pick... 10 min, 20 min, 30 min....
Test it on a copy of the db
If you are about to clear all the table entirely use TRUNCATE, not DELETE. If you want to leave some of the records then do not delete remaining 50mil all in one go, all in one transaction, as this will likely lead to transaction log expansion, which is very costly and time-consuming operation. Delete them in batches 10k-100k records at a time instead, using (GO nnnn is the SSMS directive/command hence works from SSMS only)
Alternatively, select rows which are supposed to remain into a temp table, then truncate the change log entry table, and then copy back required data.
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/