两个字段相同的表,怎样把A表数据批量导入B表中,且自动跳过重复数据?
谢谢大家!!!

解决方案 »

  1.   

    create table #a(id int,nam varchar(20))
    create table #b(id int,nam varchar(20))insert into #b select 1,'a'
    union select 1,'b'
    union select 2,'b'
    union select 2,'a'
    insert into #a select distinct * from #b
    select * from #a
    select * from #b
    drop table #a
    drop table #b
      

  2.   

    INSERT INTO tableB SELECT a.* FROM tableA as a LEFT JOIN tableB as b on a.ID = b.ID WHERE a.ID IS NULL
      

  3.   

    create table #t1(ID int)
    create table #t2(ID int)insert #t1 select 1
    union all  select 2
    union all  select 3insert #t2 select 4
    union all  select 2
    union all  select 6insert into #t2 select #t1.ID from  #t1 where #t1.ID not in(select ID from #t2 where #t2.ID=#t1.ID)select * from #t2 drop table #t1
    drop table #t2
      

  4.   


    insert into tab select * from tab1 where tab1.id not in(select id from tab)
      

  5.   

    两个字段相同的表,怎样把A表数据批量导入B表中,且自动跳过重复数据?
    谢谢大家!!!insert into b select * from a where id not in (select id from b)