方法1: 第一步: update 表1 set 表1字段=表2字段 from 表1 inner join 表2 on 表1主键=表2主键 第二步: insert into表1 select * from 表2 where not exists(select 1 from 表1 where 表1主键=表2主键)
方法2:用2008的merge,不过有点难懂。你如果是2008,去查查联机丛书吧
第一步少敲几个字吧 update 表1 set 表1字段=表2字段 from 表2 where 表1主键=表2主键
merge into tb1 as a using tb2 as b on a.主键=b.主键 when matched then update set a.字段=b.字段 when not matched then insert values(b.主键,b.字段)
第一步:
update 表1
set 表1字段=表2字段
from 表1 inner join 表2 on 表1主键=表2主键
第二步:
insert into表1
select * from 表2 where not exists(select 1 from 表1 where 表1主键=表2主键)
第一步少敲几个字吧
update 表1
set 表1字段=表2字段
from 表2 where 表1主键=表2主键
using tb2 as b
on a.主键=b.主键
when matched
then update set a.字段=b.字段
when not matched
then insert values(b.主键,b.字段)