Linked Questions

Popular Questions

Is there a better way to split work for simple updates?

Asked by At

I'm doing a MS SQL Server update of a row in a table that's very simple. I'm replacing about 4 things with another 4 things.

update Table set Column1 = 'something new' where Column1 = 'something old';
update Table set Column1 = 'something new 2' where Column1 = 'something old 2';
update Table set Column1 = 'something new 3' where Column1 = 'something old 3';
update Table set Column1 = 'something new 4' where Column1 = 'something old 4';

That's really all there is to it. But my question is, this is a table with a huge number of records running in production, but the exact number is unknown before running the updates. There is a timestamp column. And it's probably more important to update the most recent ones first.

But my question is probably a more prectical one.

Is it best to partition this up by timestamp and let it run manually, or is there a better method of letting this run? I can also divide up the work by each update statement.

Or is there some way to put such a thing into the script itself?

I've tried looking at the plans for the queries, but it doesn't tell me the best way to split it up.

Related Questions