最近帮一个客户搭建跨洋的合并复制,由于数据库非常大,跨洋网络条件不稳定,因此只能通过备份初始化,在初始化完成后向海外订阅端插入数据时发现报出如下错误:

Msg 548, Level 16, State 2, Line 2
The insert failed. It conflicted with an identity range check constraint in database %s, replicated table %s, column %s. If the identity column is automatically managed by replication, update the range as follows: for the Publisher, execute sp_adjustpublisheridentityrange; for the Subscriber, run the Distribution Agent or the Merge Agent.

 

原因?

    在SQL Server中,对于自增列的定义是对于每一条新插入的行,都会自动按照顺序新生成一个递增的数字,改数字通常和业务无关且被用于作为主键。但如果该表用于可更新事务复制或者合并复制,那么该自增列的区间范围则由复制管理。

    此时,复制可以保证自增列可控,因为复制代理插入行时不会导致自增列自增,只有用户显式插入时才会导致自增列自增。

    让我们来做一个实验。首先创建表,表定义如下:

TABLE [dbo].[Table_1](
    [c1] [int] IDENTITY(1,1),
    [c2] [int] NULL,
    [ROWGUID] [uniqueidentifier] NOT NULL,
    [rowguid4] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
 CONSTRAINT [PK_Table_1] PRIMARY KEY CLUSTERED 
(
    [c1] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

相关文章:

  • 2022-03-03
  • 2022-12-23
  • 2021-07-09
  • 2021-06-30
  • 2022-02-09
  • 2022-12-23
  • 2021-12-01
  • 2022-02-01
猜你喜欢
  • 2021-10-23
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2021-10-18
  • 2022-12-23
  • 2021-10-06
相关资源
相似解决方案