Skip to content

Automatic Primary Key Columns

DataFlex 25.0 makes it easier for developers to implement identity support in new database tables. The goal is to simplify the setup of a table and facilitate the quick creation of data entry and reporting applications.

When creating a new table in the Studio, a new option that creates a primary key column and sets the appropriate properties is available in the Create New Table dialog.

Automatic Primary Key Columns

In the past, developers had to create the column, link it to a system table via the data dictionary class for the table, or find the ‘is identity’ table attribute in the properties dialog, followed by the creation of an index for the identity column.

The new option simplifies that process and is selected by default. When deselecting it, the old way of creating tables will revert to how it was in DataFlex version 24.0 and earlier.

Depending on the type of connection selected, the new creation process differs.

For MSSQL / Other

  • A new integer column is created, named [the_table_name]ID (e.g., for the table Customer, it will be CustomerID).
  • The DF_FIELD_IS_IDENTITY attribute is set to True.
  • A primary key index is created for this new column.

For the Embedded Database

When Using a New Workspace

  • A new table, named DFLastID, is copied from the Usr\New folder to the workspace. It will use filelist slot number 270.
  • The new table dialog creates a numeric column, length 10, named [the_table_name]ID (e.g., for the table Customer, it will be CustomerID).
  • An index is created for this column.
  • A new column with the same name ([the_table_name]ID) will be created in the DFLastID table if it does not yet exist. If that column already exists, developers will be prompted to decide if it should be used. If the answer is ‘No’, a digit will be appended to the column name (e.g., CustomerID1), and the new name will be checked. This process will repeat, incrementing the digits until an appropriate column name is accepted.
  • DFLastID is checked to see if it is a system table; if not, the process will attempt to make it a system table. Note that if the DFLastID table already contains more than one record, it cannot be changed to a system table. A message will be displayed, and the column will not be added to DFLastID.
  • Upon saving the DataDictionary class file for the new table, the Studio saves the DFLastID table, and the [Field_Auto_Increment](https://docs.dataaccess.com/dataflexhelp/mergedProjects/VdfClassRef/DataDictionary-Function-Field_Auto_Increment.md) option is set for the column in the DFLastID table. The DFLastID table is automatically added to the list of externally updated tables.

When Using an Existing Workspace

  • The new table dialog creates a numeric column, length 10, named [the_table_name]ID (e.g., for the table Customer, it will be CustomerID).
  • An index is created for this column.
  • The DFLastID table will most likely not be present, and you might already have a system table in place. Therefore, you are responsible for adding the field_auto_increment option for this new column in the DataDictionary class of your existing system table.
  • Developers who would like to switch to using the DFLastID table may perform the following steps:
  • Go to the USR\New folder.
  • Copy the DFLastID files (Data and DDSrc) to the workspace.
  • Add the DFLastID table to the existing filelist (do not copy the filelist.cfg) via the Table Explorer in the Studio, preferably using number 270 as the table number (the DFLastID at a different number will still work).
  • Remap existing field_auto_increment rules to the DFLastID table.
  • Copy the contents of the current system table to DFLastID.
  • Drop the old system table.