各行をループし、反復ごとに複数のテーブルに挿入する必要がある 900 万レコードのテーブルがあります。
私のクエリ例は
//this is the table with 9 million records
create table tablename
(
ROWID INT IDENTITY(1, 1) primary key ,
LeadID int,
Title varchar(20),
FirstName varchar(50),
MiddleName varchar(20),
Surname varchar(50)
)
declare @counter int
declare @leadid int
Declare @totalcounter int
set @counter = 1
Select @totalcounter = count(id) from tablename
while(@counter < @totalcounter)
begin
select @leadid = leadid from tablename
where ROWID = @counter
--perform some insert into multiple tables
--in each iteration i need to do this as well
select * from [sometable]
inner join tablename where leadid = @leadid
set @counter = @counter + 1
end
ここでの問題は、特に各反復での結合に時間がかかりすぎることです。
誰かがこれを最適化するのを手伝ってくれませんか。