SQL Server 2000/2005 identity column + replication

爱⌒轻易说出口 提交于 2019-12-04 19:42:50

There is the option "NOT FOR REPLICATION" that can be applied to identity columns (and triggers and other constraints).

In your example, server1 would seed 1-10 but simply accept replicated 11-20.

A couple of ways to setting your seeds:

Either: set your seed/increments with NOT FOR REPLICATION like this

  • Seed 1, increment 2
  • Seed 2, increment 2
  • Seed -1, increment -2
  • Seed -2, increment -2
  • Seed 1000000001, increment 2
  • Seed 1000000002, increment 2
  • Seed -1000000002, increment -2
  • Seed -1000000001, increment -2

This gives you 500,000,000 per server for 8 servers

Or: Add a second column called ServerID to give composite keys, use NOT FOR REPLICATION for the ID column

This scales up to,say, 256 servers for tinyint with 2^32 rows per server

Either way works...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!