update T_a set aaa=T_b.aaa,bbb=T_b.bbb where aaa in (select aaa from T_b where bbb is not null)
insert into T_a(aaa,bbb) select(aaa,bbb) from T_b where aaa not in (select aaa from T_a)
建一表c
create table c
(
aaa varchar(20),
bbb varchar(30)
)
将b中数据导入c表。
更新表a中重复aaa的bbb字段
update a set a.bbb=c.bbb from a,c where a.aaa=c.aaa
插入表a中不重复的值
insert into a select aaa,bbb,null,null from c where not exists(select 1 from a where a.aaa=c.aaa)
create trigger tri_insert on A
instead of insert
as
if not exists(select a.* from A,B where A.aaa=B.aaa)
begin
insert A(aaa,bbb)
select aaa,bbb from B
end
else
begin
update A set bbb=B.bbb from B where A.aaa=B.aaa
end
go