I have a requirement where I need to update thousands of records in live database table, and although there are many columns in this table, I only need to update 2-3 columns.
Further I can't hit database for thousand times just for updating which can be done in a batch update using SQL Server Table Valued Parameter. But again I shouldn't update all thousands records in one go for better error handling, instead want to update records in batches of x*100.
So, below is my approach, please give your valuable inputs for any other alternatives or any change in the proposed process -
- 1 Fetch required records from database to
List<T> MainCollection
- 2 Save this collection to XML file with each element
Status = Pending
- 3 Take first 'n' elements from XML file with
Status = Pending
and add them to newList<T> SubsetCollection
- 4 Loop over
List<T> SubsetCollection
- make required changes toT
- 5 Convert
List<T> SubsetCollection
to DataTable - 6 Call Update Stored Procedure and pass above DataTable as TVP
- 7 Update
Status = Processed
for XML Elements corresponding toList<T> SubsetCollection
- 8 If more records with Pending status exists in XML file, go to Step# 3.
Please guide for a better approach or any enhancement in above process.