Chapter 7. SQL Remote Design for AdaptiveSer verAnywhere
Ensuring unique primary keys
Primarykey values must be unique. Whenall users are connected to the
samedatabase, there is no problem keeping unique values. Ifa user tries to
re-usea value, the INSERT statement fails.
Thesituation is different in a replication system because users are connected
tomany databases. Apotential problem arises when two users, connected to
differentdatabases, insert a row using the same primary key value. Each of
theirstatements succeeds because the value is unique in each database.
However,problems arise in a replication system when two users, connected
toseparate databases, INSERT a row using the same primary key value. The
secondINSERT to reach a given database in the replication system fails. As
SQLRemote is a replication system for occasionally connected users, there
canbe no locking mechanism across all databases in the installation. Itis
necessaryto design your SQL Remote installation so that primary key
duplicationerrors do not occur.
Forprimary key errors to be designed out of SQL Remote installations, the
primarykeys of tables that may be modiļ¬ed at more than one site must be
guaranteedunique. Thereare several ways of achieving this goal. This
chapterdescribes two general, economical, and reliable methods.
1. Using the default global autoincrement feature of Adaptive Server
Anywhere.
2. Using the primary key pools to maintain a list of unused, unique primary
keyvalues at each site.
Youcan use these techniques either separately or together to avoid duplicate
values.

Using global autoincrement default column values

InAdaptive Server Anywhere, you can set the default column value to be
GLOBALAUTOINCREMENT. Youcan use this default for any column in
whichyou want to maintain unique values, but it is particularly useful for
primarykeys. Thisfeature is intended to simplify the task of generating
uniquevalues in setups where data is being replicated among multiple
databases,typically by MobiLink synchronization.
Whenyou specify default global autoincrement, the domain of values for
thatcolumn is partitioned. Eachpartition contains the same number of
values. For example, if you set the partition size for an integercolumn in a
databaseto 1000, one partition extends from 1001 to 2000, the next from
2001to 3000, and so on.
129