Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
CodeDatabaseDelphiRAD Studio

Learn How To Implement Auto-Incremental Fields In This FireDAC.AutoincFields Sample For Delphi

FireDAC allows the insertion of a new record with an auto-incrementing column and getting back a new value of this column. That works for immediate updates, as well as for cached updates. Depending on the DBMS, the auto-incrementing fields may be implemented either using a special IDENTITY (or similar) column data type, or using a generator (or a sequence) and a table trigger


You can find the AutoincFields sample project at:

  • Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to:
    • Object Pascal\Database\FireDAC\Samples\DApt Layer\Autoinc fields
  • Subversion Repository:
    • You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.


The AutoincFields sample shows you how to work with auto-incremental fields using FireDAC. To this end, the sample uses the TFDDatSColumn class to control the client-side and the server-side auto-incrementing fields. Concretely, the sample uses the TFDDatSColumn.ServerAutoIncrement property of TFDDatSColumn to specify when the DBMS generates an auto-incrementing value for the new record column.

How to Use the Sample

  1. Navigate to the location given above and open AutoInc.dproj.
  2. Press F9 or choose Run > Run.
  3. Click on the Use Connection Definition combo box and select an option.


File in DelphiContains
The project itself.
The main form.


The sample implements the following features.

Create schema adapter

To this end, the sample uses FDCreateInterface. See the following code:

Add master table adapter

The sample adds the master table adapter and sets some configuration properties, such as the ServerAutoIncrement property. See the following code:

Note: setting the ServerAutoIncrement property to True automatically assigns the AutoIncrementSeed and AutoIncrementStep properties to -1.

Add detail table adapter

The sample adds a detail table adapter and sets up some features. To this end, the sample adds the following code:

Add constraints to the DatSManager

To this end, the sample uses the Constraints property of TFDDatSTable. See the following code:

Add new row to the master table

Post changes to RDBMS

Finally, the sample updates the changes with the Update method. Then, the sample uses the Reconcile method to obtain the error information for each record that could not be applied.

To see the original post, please refer to the link below:


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.