每当远程用户添加一个新客户时,远程用户的可用主键池中的主键就会减少 1 个。因此,您需要定期补充统一数据库的主键池表中的内容,然后将新的主键复制到远程数据库。
在统一数据库中,创建一个过程来填充主键池。
因为不会复制触发器操作,所以不能使用触发器来补充键池。
例如:
CREATE PROCEDURE ReplenishPool() BEGIN FOR EachTable AS TableCursor CURSOR FOR SELECT table_name AS CurrTable, max(value) as MaxValue FROM KeyPool GROUP BY table_name DO FOR EachRep AS RepCursor CURSOR FOR SELECT location AS CurrRep, COUNT(*) AS NumValues FROM KeyPool WHERE table_name = CurrTable GROUP BY location DO // make sure there are 100 values. // Fit the top-up value to your // requirements WHILE NumValues < 100 LOOP SET MaxValue = MaxValue + 1; SET NumValues = NumValues + 1; INSERT INTO KeyPool (table_name, location, value) VALUES (CurrTable, CurrRep, MaxValue); END LOOP; END FOR; END FOR; END; |
在主键池中,为每个用户插入一个初始主键值。
ReplenishPool 过程要求对于每个预订者都至少存在一个主键值,这样它可以找到最大值并加 1 以生成下一个集合。
要实现池的初始填充,可以为每个用户插入单个值,然后调用 ReplenishPool 来填充其余部分。以下示例针对三个远程用户和一个名为 Office 的统一用户说明了此过程:
INSERT INTO KeyPool VALUES( 'Customers', 40, 'user1' ); INSERT INTO KeyPool VALUES( 'Customers', 41, 'user2' ); INSERT INTO KeyPool VALUES( 'Customers', 42, 'user3' ); INSERT INTO KeyPool VALUES( 'Customers', 43, 'Office'); CALL ReplenishPool(); |
ReplenishPool 过程会为每个用户将池一直填充到 100 个值。所需要的值取决于用户在数据库的表中插入行的频率。
定期运行 ReplenishPool。
必须定期在统一数据库运行 ReplenishPool 过程以补充键池表中的主键值池。
![]() |
使用DocCommentXchange讨论此页。
|
版权 © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |