SQL中如何实现两个不同数据库的用户表实时同步?

2024-12-01 01:23:15
推荐回答(2个)
回答1:

--同步新增的正敬蚂数据稿胡
insert into srv_lnk.test.dbo.[user]
select id,number,name from [user] where state is null
--同步修改的数据
update srv_lnk.test.dbo.[user] set
number=b.number,name=b.name
from srv_lnk.test.dbo.[user] a
join [user] b on a.id=b.id
where b.state=1
--同举埋步删除的数据
delete from srv_lnk.test.dbo.[user]
where id not in(select id from [user])

回答2:

每个表上建相关的存储触发器就可以了