Using global autoincrement

In SQL Anywhere and UltraLite databases, you can set the default column value to be GLOBAL AUTOINCREMENT. You can use this default for any column in which you want to maintain unique values, but it is particularly useful for primary keys.

Global autoincrement values are partitioned among remote databases in contiguous ranges of values. The set of possible values is finite, so the larger the size of the each range, the fewer ranges are available. Care must be taken to set the correct size of the range for your needs. Exhausting a range is possible, but you can detect this and assign a new range. See How default values are chosen.

 To use global autoincrement columns
  1. Declare the column as a global autoincrement column.

    When you specify default global autoincrement, the domain of values for that column is partitioned. Each partition contains the same number of values. For example, if you set the partition size for an integer column in a database to 1000, one partition extends from 1001 to 2000, the next from 2001 to 3000, and so on.

    See Declaring default global autoincrement.

  2. Set the global_database_id value.

    SQL Anywhere and UltraLite databases supply default values in a database only from the partition uniquely identified by that database's number. For example, if you assign a database the identity number 10 and the partition size is 1000, the default values in that database would be chosen in the range 10001-11000. Another copy of the database, assigned the identification number 11, would supply default value for the same column in the range 11001-12000.

    See Setting the global database ID.


Declaring default global autoincrement
Setting the global database ID