两个字段相同的表,怎样把A表数据批量导入B表中,且自动跳过重复数据?该怎么解决...

两个字段相同的表,怎样把A表数据批量导入B表中,且自动跳过重复数据?该怎么解决

www.MyException.Cn   发布于:2012-03-24 14:00:46   浏览:19次
 
两个字段相同的表,怎样把A表数据批量导入B表中,且自动跳过重复数据? 两个字段相同的表,怎样把A表数据批量导入B表中,且自动跳过重复数据? 谢谢大家!!!
------解决方案-------------------------------------------------------- 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 ------解决方案-------------------------------------------------------- INSERT INTO tableB SELECT a.* FROM tableA as a LEFT JOIN tableB as b on a.ID = b.ID WHERE a.ID IS NULL ------解决方案-------------------------------------------------------- create table #t1(ID int) create table #t2(ID int)
insert #t1 select 1 union all  select 2 union all  select 3
insert #t2 select 4 union all  select 2 union all  select 6
insert 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 ------解决方案-------------------------------------------------------- insert into tab select * from tab1 where tab1.id not in(select id from tab) ------解决方案-------------------------------------------------------- 两个字段相同的表,怎样把A表数据批量导入B表中,且自动跳过重复数据? 谢谢大家!!!
insert into b select * from a where id not in (select id from b)

转载于:https://www.cnblogs.com/mywater/p/3277398.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值