我见过一些与在数据库上复制数据的软件有关的问题,但我还没有看到一个能满足我的需要的问题。我需要把许多奴隶复制给一个主人。主人将把来自奴隶的所有数据合并到它的表中。下面的场景应该有助于解释我要找的是什么:
每台机器使用SQLite具有相同的表/DB布局。对于这些示例,我将使用列时间戳、MachineNumber、PointName、Value的一个表:
机1上的DB表
00:00:00 1 Point1 1.0
00:00:00 1 Point2 2.1
00:00:01 1 Point1 1.5
00:00:01 1 Point2 2.1机2上的DB表
00:00:00 2 Point1 2.0
00:00:00 2 Point2 3.1
00:00:01 2 Point1 2.1
00:00:01 2 Point2 3.0DB on主程序(需要从每个从站复制,以及由于连接丢失而增加的增量)
00:00:00 1 Point1 1.0
00:00:00 1 Point2 2.1
00:00:00 2 Point1 2.0
00:00:00 2 Point2 3.1
00:00:01 1 Point1 1.5
00:00:01 1 Point2 2.1
00:00:01 2 Point1 2.1
00:00:01 2 Point2 3.0发布于 2017-04-24 15:59:28
尝试:
sqlite3 db-master
sqlite> attach 'db1' as db1;
sqlite> attach 'db2' as db2;
sqlite> insert or ignore into data select * from db1.data;
sqlite> insert or ignore into data select * from db2.data;注意:如果从表中的数据不断累积,您可能需要在数据上定义一个唯一的ID,这样每次与主数据库同步时,都不会重新添加相同的信息。
https://stackoverflow.com/questions/43590044
复制相似问题