I came across a piece of code in a sql stored proc in our code base where it was using chunking without transaction block. I don’t see how chunking could be beneficial without tran block? I've been humbled a few times when I've jumped into conclusion without digging more, so what advantage does chunking without tran block offer? Is there any?
The pseudocode is something like:
Populate the Main temptable (ID, Name, UpdatedFlag). This flag column indicates whether the record has been updated or not.
Start while loop (do as long as there is a record in MainTable with UpdatedFlag = 0)
- Only select the given chunkSize into ChunkSizeMain tempTable (ID, Name) from the records that hasn’t been marked as updated
- Begin TRY block
- Start updating some other table by joining on ID of ChunkSizeMainTable.
- Update UpdatedFlag = 1 in MainTable.
- End try
- Begin catch //some action End Catch