Managing SERIALs in a generated application

Primary keys you define as SERIAL are managed by the BAM using a table named seqreg in the meta-schema (4dbx). BAM uses this table to provide a sequence of unique integer numbers for SERIAL columns keys.

The seqreg table

For generated applications, BAM automatically adds a seqreg table to a new meta-schema (4dbx). It contains two columns; one with the name of the table having a SERIAL column and one with the last SERIAL column value for that table. Thus one seqreg table facilitates a sequence number management for all tables with SERIAL columns in the database.

When a new row is inserted in a table, the BAM provides the primary key value by auto-incrementing the last serial column value entered for the table.

No configuration required

Once you have created a table with a SERIAL defined as the primary key, BAM manages sequence number generation and generates all code necessary to handle inserting the new sequence number during an Add operation. No additional configuration or modeling is required.

You may initialize the seqreg table with the appropriate records otherwise SERIAL columns will start at number 1.

If the database schema does not contain SERIAL columns, the seqreg table is not required in the schema.

Informix databases

The seqreg table is required in a schema containing SERIAL columns except for Informix® databases where the native Informix SERIAL management is used.

For further information on how the seqreg table is used, see Solution 2: Generate serial numbers from your own sequence table in the Genero Business Development Language User Guide.