I have looked at some resources already and just want to clarify and get an opinion.
我已经查看过一些资源,只想澄清并得到意见。
First of all to totally avoid any problems we could just not bother using identity columns as primary keys instead have them generated ourselves and just have those values replicated both ways presuming they are always unique at any time of creation.
首先,为了完全避免任何问题,我们可以不打扰使用标识列作为主键,而是让它们自己生成,只是让这些值以两种方式复制,假设它们在创建的任何时候都是唯一的。
For the purposes of this question I am talking about 2 or more way replication to solve global access issues and we do have identity columns.
出于这个问题的目的,我说的是解决全局访问问题的2种或更多种方式复制,我们确实有标识列。
Now we are setting up transactional replication and both databases should replicate to each other.
现在我们正在设置事务复制,两个数据库应该相互复制。
As I understand it you allocate a range of seed values to each database server and it will use these, you know there unique cause you gave ranges that do not cross. So does this mean during replication these values are inserted into the seed column?
据我所知,你为每个数据库服务器分配一系列种子值,它会使用这些,你知道你给出了不交叉范围的唯一原因。那么这意味着在复制过程中这些值是否会插入到种子列中?
so if you allocate ranges 1-10 and 11-20 to 2 servers once each server has inserted 10 rows you will have seeds 1-20 in both databases?
所以,如果你在每个服务器插入10行后将范围1-10和11-20分配给2个服务器,那么在两个数据库中都会有种子1-20?
1 个解决方案
#1
4
There is the option "NOT FOR REPLICATION" that can be applied to identity columns (and triggers and other constraints).
有一个选项“NOT FOR REPLICATION”可以应用于标识列(以及触发器和其他约束)。
In your example, server1 would seed 1-10 but simply accept replicated 11-20.
在您的示例中,server1将播种1-10,但只接受复制11-20。
A couple of ways to setting your seeds:
设置种子的几种方法:
Either: set your seed/increments with NOT FOR REPLICATION like this
要么:像这样设置NOT FOR REPLICATION你的种子/增量
- Seed 1, increment 2
- 种子1,增量2
- Seed 2, increment 2
- 种子2,增量2
- Seed -1, increment -2
- 种子-1,增量-2
- Seed -2, increment -2
- 种子-2,增量-2
- Seed 1000000001, increment 2
- 种子1000000001,增量2
- Seed 1000000002, increment 2
- 种子1000000002,增量2
- Seed -1000000002, increment -2
- 种子-1000000002,增量-2
- Seed -1000000001, increment -2
- 种子-1000000001,增量-2
This gives you 500,000,000 per server for 8 servers
这为8台服务器提供了每台服务器500,000,000个
Or: Add a second column called ServerID to give composite keys, use NOT FOR REPLICATION for the ID column
或者:添加名为ServerID的第二列以提供复合键,对ID列使用NOT FOR REPLICATION
This scales up to,say, 256 servers for tinyint with 2^32 rows per server
例如,这可以扩展到256个服务器,用于tinyint,每个服务器有2 ^ 32行
Either way works...
无论哪种方式都有效......
#1
4
There is the option "NOT FOR REPLICATION" that can be applied to identity columns (and triggers and other constraints).
有一个选项“NOT FOR REPLICATION”可以应用于标识列(以及触发器和其他约束)。
In your example, server1 would seed 1-10 but simply accept replicated 11-20.
在您的示例中,server1将播种1-10,但只接受复制11-20。
A couple of ways to setting your seeds:
设置种子的几种方法:
Either: set your seed/increments with NOT FOR REPLICATION like this
要么:像这样设置NOT FOR REPLICATION你的种子/增量
- Seed 1, increment 2
- 种子1,增量2
- Seed 2, increment 2
- 种子2,增量2
- Seed -1, increment -2
- 种子-1,增量-2
- Seed -2, increment -2
- 种子-2,增量-2
- Seed 1000000001, increment 2
- 种子1000000001,增量2
- Seed 1000000002, increment 2
- 种子1000000002,增量2
- Seed -1000000002, increment -2
- 种子-1000000002,增量-2
- Seed -1000000001, increment -2
- 种子-1000000001,增量-2
This gives you 500,000,000 per server for 8 servers
这为8台服务器提供了每台服务器500,000,000个
Or: Add a second column called ServerID to give composite keys, use NOT FOR REPLICATION for the ID column
或者:添加名为ServerID的第二列以提供复合键,对ID列使用NOT FOR REPLICATION
This scales up to,say, 256 servers for tinyint with 2^32 rows per server
例如,这可以扩展到256个服务器,用于tinyint,每个服务器有2 ^ 32行
Either way works...
无论哪种方式都有效......