Monthly Archives: February 2014 - Page 2

Update Massive Table in smaller Batches or Transactions

[cc lang=”sql”]

SET NOCOUNT ON

DECLARE @BatchSize INT, @BatchCount INT, @totalCount INT

SET @BatchSize = 10000
SET @BatchCount = 0

SET @totalCount = (SELECT COUNT(*) FROM states)
WHILE EXISTS(SELECT * FROM states where desc like ‘%US%’)
BEGIN

UPDATE TOP (@BatchSize) states
set desc = ‘United States of America’
where desc like ‘%US%’

SET @BatchCount = @BatchCount + @@ROWCOUNT
END

SET NOCOUNT OFF

[/cc]