Hello, there is a table tst_ex1 containing 2 fields: id int identity (0,1) , gui uniqueidentifier null . And the tst_ex2 table contains the gui2 uniqueidentifier null field. From the tst_ex1 table containing 3 million rows I want to insert a million rows into the tst_ex2 table, but the algorithm developed by me performs this operation extremely slowly (data insertion will take more than a week), since most of the time, there is a check of all 3 million lines for compliance with the where clause (code below):
use Test go declare @b int = 0; while @b < 1000000 begin insert into dbo.tst_ex2 (tst_ex2.gui2) select tst_ex1.gui from dbo.tst_ex1 where tst_ex1.id = @b; set @b += 1; end;
Help speed up the insertion process. I read about bcp , but in practice I did not understand how to use it.
insert into dbo.tst_ex2 (tst_ex2.gui2) select tst_ex1.gui from dbo.tst_ex1 where tst_ex1.id<100000
not tried? - Yura Ivanovtst_ex1
there any index on thetst_ex1
table, or is it an index-free heap? 2. Paste not one by one, but in pieces, say, 10,000... where tst_ex1.id between @b and @b + 10000
(... where tst_ex1.id between @b and @b + 10000
). - Yaant