Sunday, August 14, 2011

Use MySQL's Modulo Operator to Update in Batches

Sometimes you need to roll out your nefarious plan slowly and MySQL's modulo operator can help.  Here we do the first of ten batches:
UPDATE
Task t INNER JOIN
TaskDescriptor td ON t.TaskDescriptorId = td.Id
SET
t.StartTime = NOW()
WHERE
td.Type = 'nefarious plan' AND
t.Id % 10 = 0;
view raw gistfile1.sql hosted with ❤ by GitHub