Can be used with MySQL, PostgreSQL, SQL Server, and Microsoft Access to get the value of the ID field after executing INSERT statement.
property LastInsertId: Int64;
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.