I have 17 millions rows in my table, some of them contain an URL in the [url] column, and I want to replace some part of the URL in all my rows.
I have 8 millions rows in my table that need to be updated.
I already optimized my query a little, doing the replace by batches of 4,000, but it's still taking very long:
declare @Rows INT,
@BatchSize INT;
SET @BatchSize = 4000;
SET @Rows = @BatchSize; -- initialize just to enter the loop
while (@Rows = @BatchSize)
BEGIN
UPDATE TOP (@BatchSize) [dbo].[table]
SET
[url] = replace([url],
'?sv=2019-12-12&foo=bar',
'?sv=2020-02-10&bar=foo')
where [url] like '%foo=bar'
END;
Do you have any idea how I can improve this task?