Wednesday, 22 July 2015

TSQL: Batching Modifications with TOP

Able to cap the number of rows for a specific insert, update, or delete operation
Avoids monolithic transation


Sample:

while (select count(*) from table1
           where modifieddate < '2012-09-05'
          ) > 0
begin
         update top(500) table1
         set actualcost *= 1.05
         where modifieddate < '2012-05-05'
end

No comments:

Post a Comment