KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Changing the sequence number of a table
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: July 8, 2024

When working with records that use integers as primary keys, you may find that 4D would try to assign any new records with a number that has already been in use. This could be happen when autoincrement is on for the record table, but the developer had been setting the record ID manually, and then attempting to use CREATE RECORD to make a new record.

This happens because when autoincrement is checked off for a table, it keeps a counter that increments by 1 every time a new record is created for the table. This counter can be accessed using the command Sequence number, and represents the ID number for the next record created for the table. This makes it so numbers assigned are never reused in the table, given that the creation and deletion of records are programmatic and there isn’t any pieces of code that tries to have set the ID number manually.

To change the sequence number, please run the piece of code below in your application, with "[Table]" and "Value" replaced with your own values:

SET DATABASE PARAMETERS([Table]; Table sequence number; Value)

The next record created in [Table] will have an ID number of "Value+1," and will solve the duplicate error.

Please note: Sequence number is no longer the preferred option as unique ID primary keys for records, as the internal counter could become desynchronized when using several data files, or when trying to manually set the ID number. It is recommended to use UUIDs for unique record IDs, as they are unique between tables and databases.