更新时间:2022-01-11 06:49:28
在表格之间移动数据的最简单方法之一是:
One of the simplest ways to move data between tables in chunks is:
DECLARE @CHUNK_SIZE int = 10000;
DECLARE @RC int = @CHUNK_SIZE;
WHILE @RC >0
BEGIN
INSERT INTO TargetTable (Mycolumns)
SELECT TOP @CHUNK_SIZE Mycolumns
FROM SourceTable
WHERE Conditions
;
SET @RC = @@ROWCOUNT
;
END
条件需要排除已处理的行。
性能主要取决于这些条件(和索引)。
您可以使用 NOT EXISTS
,或使用有序查询并设置变量= Max(ID)来自输出子句,或者你可以从Sourcetable中删除已处理的行。
但是你已经被告知,我们没有足够的信息告诉你***的方法。
Where the conditions need to exclude already processed rows.
The performance is mostly depending on these conditions (and indexes).
You can for example use NOT EXISTS
, or use an ordered query and set a variable = Max(ID) from the output clause, or you can remove processed rows from the Sourcetable.
But as you've already been told, we don't have enough information to tell you the best way.