Thanks in advance
SELECT @id = min(id) FROM tbl
SELECT @incr = 50000
WHILE EXISTS (SELECT * FROM tbl WHERE id >= @id
BEGIN
UPDATE tbl
SET col = ...
WHERE id BETWEEN @id AND @id + incr - 1
SELECT @id = @id + @incr
END
Here I've assumed that id is an integer, but it can also work with dates,
in which case you need to find a good interval. Maybe 30 days.
The other where to go is
WHILE 1 = 1
BEGIN
UPDATE TOP(@batchsize)
SET col = ...
WHERE ...
SELECT @@rowcount= @rowc
IF @rowc <> @batchsize
BREAK
END
This presumes that can identify which rows you have processed.
The first method is likely to be faster, since SQL Server does not
have to scan the table each iteration.
Then again, for only 3.2 million rows I might consider doing it all
at once, unless it's a LOB column you are updating.
--
Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se
Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx