Last active
May 23, 2017 06:46
-
-
Save RajatGoyal/555152b3ce5b052b539686fee22f9389 to your computer and use it in GitHub Desktop.
copy data in batches from one table another, so that transfer does not happen in a single transactions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @BatchSize INT = 20000 | |
declare @StartId = 0; | |
declare @MaxId; | |
select @MaxId = max(Id) from [dbo].[SOURCE] . | |
WHILE 1 = 1 | |
BEGIN | |
INSERT INTO [dbo].[Destination] | |
SELECT * | |
FROM [dbo].[SOURCE] | |
WHERE id between @StartId and @StartId + @BatchSize; | |
SET @StartId = @StartId + @BatchSize | |
IF @StartId > @MaxId BREAK | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment