I will leave my answer here, since I was able to test various approaches for mass removal and updating (I had to update and then delete 125 million lines, the server has 16 GB of RAM, Xeon E5-2680 @ 2.7 GHz, SQL Server 2012).
TL; DR : always update / delete by primary key, and not by any other conditions. If you cannot use PK directly, create a temporary table and fill it with PK values and update / delete your table using this table. Use indexes for this.
I started with a solution from above (@Kevin Aenmey), but this approach turned out to be inappropriate, since my database worked and processes a couple of hundred transactions per second, and there was some lock (there was an index for all the fields there from the condition, using WITH(ROWLOCK) nothing has changed).
So, I added the WAITFOR , which allowed the database to process other transactions.
deleteMore: WAITFOR DELAY '00:00:01' DELETE TOP(1000) FROM MyTable WHERE Column1 = @Criteria1 AND Column2 = @Criteria2 AND Column3 = @Criteria3 IF @@ROWCOUNT != 0 goto deleteMore
This approach was able to process ~ 1.6 million lines / hour for updating and ~ 0.2 million lines / hour for removal.
The transition to temporary tables has changed a lot.
deleteMore: SELECT TOP 10000 Id INTO
This solution processed ~ 25 million lines / hour to update (15 times faster) and ~ 2.2 million lines / hour to delete (11 times faster).
Marko Juvančič Mar 06 '19 at 10:39 2019-03-06 10:39
source share