SQL Server 2000/2005 标识列 + 复制 [英] SQL Server 2000/2005 identity column + replication

查看:36
本文介绍了SQL Server 2000/2005 标识列 + 复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经查看了一些资源,只是想澄清一下并获得意见.

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.

出于这个问题的目的,我谈论的是解决全局访问问题的 2 种或多种复制方式,我们确实有标识列.

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.

现在我们正在设置事务复制,两个数据库应该相互复制.

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?

因此,如果在每个服务器插入 10 行后将范围 1-10 和 11-20 分配给 2 个服务器,那么两个数据库中都会有 1-20 个种子?

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?

推荐答案

有选项NOT FOR REPLICATION" 可应用于标识列(以及触发器和其他约束).

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

在你的例子中,server1 将播种 1-10,但只接受复制的 11-20.

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

设置种子的几种方法:

或者:像这样用 NOT FOR REPLICATION 设置你的种子/增量

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

  • 种子 1,增量 2
  • 种子 2,增量 2
  • 种子 -1,增量 -2
  • 种子 -2,增量 -2
  • 种子 1000000001,增量 2
  • 种子 1000000002,增量 2
  • 种子 -1000000002,增量 -2
  • 种子 -1000000001,增量 -2

这为 8 个服务器的每台服务器提供了 500,000,000 个

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

或者:添加名为 ServerID 的第二列以提供组合键,ID 列使用 NOT FOR REPLICATION

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

对于 tinyint,这可以扩展到 256 个服务器,每个服务器有 2^32 行

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

无论哪种方式都有效...

Either way works...

这篇关于SQL Server 2000/2005 标识列 + 复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆