create proc proname
@BatchID varchar(50) --批次
as
update A set
Name=B.Name
from B
where B.ID=A.ID and A.BatchID=@BatchID
insert into A
(
select
ID,Name
from B b where not exists (select 1 from A where A.ID=b.ID and b.BatchID=@BatchID)
delete B where BatchID=@BatchID
@BatchID varchar(50) --批次
as
update A set
Name=B.Name
from B
where B.ID=A.ID and A.BatchID=@BatchID
insert into A
(
ID,Name
)select
ID,Name
from B b where not exists (select 1 from A where A.ID=b.ID and b.BatchID=@BatchID)
delete B where BatchID=@BatchID
go
创建临时表
create table #a
(
ID int,
Name varchar(10)
)