UniDAC

TUniSQL.LastInsertId Property

Can be used with MySQL, PostgreSQL, SQL Server, and Microsoft Access to get the value of the ID field after executing INSERT statement.

Class

TUniSQL

Syntax

property LastInsertId: Int64;

Remarks

The LastInsertId property retrieves the value of an ID field after executing an INSERT statement in MySQL, PostgreSQL, SQL Server, and Microsoft Access.

MySQL:

In MySQL, the LastInsertId property retrieves the ID generated for an AUTO_INCREMENT column by the most recent query. Use this property after performing an INSERT into a table with an AUTO_INCREMENT field.

PostgreSQL:

In PostgreSQL, the LastInsertId property returns the OID value generated for an OID column in tables with OIDs by the previous query.

SQL Server:

In SQL Server, the LastInsertId property retrieves the last identity value generated in any table during the current session. The property relies on the @@IDENTITY function and requires an additional request to the server to fetch the value.

Microsoft Access:

In Microsoft Access, the LastInsertId property retrieves the value generated by the most recent query for a primary key column of type AutoNumber. Use this property after performing an INSERT into a table with an AutoNumber primary key.

If the query does not perform insertion into a table that contains field of the types specified above, the value of LastInsertId won't be defined.

© 1997-2025 Devart. All Rights Reserved. Request Support DAC Forum Provide Feedback