2

我有这样的场景:

我有很多机器,每台机器上都有数据库。还有一台客户端机器可以从所有机器中提取数据并添加到他的本地数据库中(它可能有以前下载的数据)。因此,“许多”数据库上的表需要一些唯一标识符。

many- 每台机器上的数据库

merged- 从数据库中提取数据的客户端计算机上的many数据库。

我的两个想法:

  1. GUIDmany数据库和GUID合并数据库中的主键。在这里,我还需要机器的列 id 来区分机器之间的行。

  2. 数据库中的整数主键many和合并中的复合键(机器的 GUID id +many数据库中的整数主键)

    这里我假设每个many数据库本身不需要 GUID,而只需要merged一个,所以 GUID 是唯一需要的merged,它是一个复合键。

对于这种情况,什么是更好的选择?也许我错过了什么。

4

1 回答 1

0

GUID is ideal for such a system - it practically ensures that no primary key collisions will occur. Since you are designing it, you can use GUIDs as temporary identifiers in your many databases and replace them with integer keys in the merged one.

Another option is to partition the ID's between the many databases, so each can only use a range of IDs that non of the others can use. This is not trivial to do well (i.e. without having an estimate of how long these databases can exist without resync you may "overflow", you need to be able to offer additional ranges once a database "runs out" etc...) and may not suit your particular needs.

于 2012-05-12T20:24:02.750 回答