• Please check this code:

    -- Session 1

    declare

    @from_id int = 0

    ,@to_id int = 0

    ,@rowcnt int = -1

    create table ##tmp_move_date (id int primary key, from_id int, rowcnt int)

    insert into ##tmp_move_date (id, from_id, rowcnt ) values (1, 0, 0)

    select @from_id = from_id from ##tmp_move_date where id = 1

    while (@rowcnt <> 0)

    begin

    select top 1000000 @to_id = id from old_table where id > @from_id order by id

    begin tran

    insert into new_table <fields>

    select <fields> from old_table where id between @from_id and @to_id

    -- order by id

    set @rowcnt = @@ROWCOUNT

    set @from_id = @to_id + 1

    update ##tmp_move_date

    set from_id = @from_id,

    rowcnt = rowcnt + @rowcnt

    commit

    end

    -- Session 2: Monitoring

    select * from ##tmp_move_date (nolock)