UniDAC

TUniSQL.LastInsertId Property

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

Class

TUniSQL

Syntax

property LastInsertId: Int64;

Remarks

The LastInsertId property can be used with MySQL, PostgreSQL, and SQL servers to get the value of the ID field after executing INSERT statement.

For MySQL LastInsertId returns the ID generated for an AUTO_INCREMENT column by the previous query. Use this property after you have performed an INSERT query into a table that contains an AUTO_INCREMENT field.

For PostgreSQL LastInsertId returns the OID value generated for an OID column in a table with OIDs by the previous query.

For SQL Server, the last identity value is generated in any table in the current session. The function @@IDENTITY is used to identify the last-inserted identity value. To get the value, it's required to run an adiitional request to the server.

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-2024 Devart. All Rights Reserved. Request Support DAC Forum Provide Feedback