insert into B
select * from A where not exists (select 1 from B where B.col=A.col)
--插入A-B的数据
--覆盖数据
update B
set 字段1=A.字段1,字段2=A.字段2
from A 
where B.主键=A.主键

解决方案 »

  1.   

    谢谢!
    如果又要a全部导入b。又要覆盖b的相同id的数据呢?
      

  2.   

    那就是这样.
    delete from b
    where col in (select col from a)insert into B
    select * from A
      

  3.   

    create proc insertab 
    as
    declare @a int,@b varchar(10)... --有多少列就定义多少变量
    declare @a1 int
    select @a1=id from table1        --将最后一条值主键赋给@a1
    select @a=0
    ...                              --对它们赋初始值吧
    declare cur cursor for select * from table2
    open cur
    fetch next from cur into @a,@b,...-- 一定要完全
    while @@fetch_status=0
    begin
    set @a=@a+@a1 
    insert into table1 values(@a,''+@b+'',...) --完全
    fetch next from cur into @a,@b,...
    end
    close cur
    deallocate curgo最笨的方法,楼主试一下吧!