最终目的是将所有数据插入目标表,请问为什么要分多次呢?

解决方案 »

  1.   


    create proc indata @count int=5,@tablename varchar(10)
    as
    begin
    if(@tablename='source_1')
    begin
    insert into target_1
    select top(@count) id,name,sex,dept,sal from source_1
    where id >(select max(id) from node where 表名='source_1') order by id 
    insert into node
    select (select max(id) from node where 表名='source_1'),'source_1'
    end
    else
    begin
    insert into target_2
    select top(@count) id,name,sex,dept,sal from source_2
    where id >(select max(id) from node where 表名='source_2') order by id 
    insert into node
    select (select max(id) from node where 表名='source_2'),'source_2'
    end
    end试试吧,没测试...
      

  2.   

    使用一张临时表,记录 当前的最大编号,更新数据后及时更新此表
      

  3.   

    如果源数据相当大,不能够一次全部插入,就要分多次,就需要记录上次插到了源数据表的哪条数据