SQL 同步表


begin tran

------取得备份表中所有的ID-------
with bakid as(
    select id from dt_A_bak
)

------根据ID,筛选出,两张表之间的差集-------

select * 
into #dt_A_Exc
from dt_A where id not in (
    select * from bakid
)

------根据ID,筛选出,两张表之间的差集-------

------根据ID,筛选出,两张表之间的交集-------

select * 
into #dt_A_Inter
from dt_A where id in (
    select * from bakid
)

------根据ID,筛选出,两张表之间的交集-------

--插入
insert into dt_A_bak
select * from #dt_A_Exc

--更新
update dt1 set dt1.name = dt2.name
from dt_A_bak dt1
inner join dt_A dt2 on dt1.id = dt2.id
where dt1.id in (
    select id from #dt_A_Inter
)

select * from dt_A
select * from dt_A_bak

rollback tran

知识共享许可协议
《SQL 同步表,没有添加,有就更新》 常伟华 创作。
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议 | 3.0 中国大陆许可协议进行许可。

站内公告

A PHP Error was encountered

Severity: Core Warning

Message: PHP Startup: zip: Unable to initialize module Module compiled with module API=20060613 PHP compiled with module API=20090626 These options need to match

Filename: Unknown

Line Number: 0

Backtrace: