V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
zhangshaohan
V2EX  ›  数据库

请教各位大佬一个数据库更新的问题

  •  
  •   zhangshaohan · Nov 21, 2019 · 2228 views
    This topic created in 2349 days ago, the information mentioned may be changed or developed.

    现有如下逻辑: 1、有两个数据库,一个原库,一个资源库 2、原库部分数据更新,资源库对应数据无修改,全量更新 3、原库部分数据更新,资源库对应数据修改过的不更新

    请问有没有好的办法实现这个逻辑呢?

    4 replies    2019-12-03 16:30:09 +08:00
    starerlloll
        1
    starerlloll  
       Nov 21, 2019
    不太懂 你说的“修改过 /无修改” 是怎么判定的,是从来就没修改过呢,还是某个时间段内没修改过
    zhangshaohan
        2
    zhangshaohan  
    OP
       Nov 21, 2019
    @starerlloll 只要原库一条数据中某个字段被修改了,那就算修改过
    starerlloll
        3
    starerlloll  
       Nov 21, 2019
    @Geekerstar 那加个 hasChange 的变量进去不就好了
    065535
        4
    065535  
       Dec 3, 2019
    使用整行匹配来更新资源库的数据。
    update t1 set id=x1 , name=x2, xx=x3 where id=xx and name=xx and xx=xx....

    如果资源库没有修改,那么 where 是能够和源库前镜像匹配的,这时候可以匹配上数据并执行更新。
    如果资源库有修改,那么 where 后的条件是匹配不上资源库上的记录的,也就更新不到这个数据。
    这样就能完成你的业务了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5380 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 01:14 · PVG 09:14 · LAX 18:14 · JFK 21:14
    ♥ Do have faith in what you're doing.