EPUB | CHM | PDF

TMySQLDataSet.Methods.GetLastInsertID

Top Previous Next

Returns the ID generated for an AUTO_INCREMENT column by the previous query.

Syntax:

procedure GetLastInsertID: Int64;

Description:

Use this function after you have performed an INSERT query into a table that contains an AUTO_INCREMENT field.

Note that GetLastInsertID returns 0 if the previous query does not generate an AUTO_INCREMENT value. If you need to save the value for later, be sure to call GetLastInsertID immediately after the query that generates the value.

Also note that the value of the SQL LAST_INSERT_ID function always contains the most recently generated AUTO_INCREMENT value, and is not reset between queries because the value of that function is maintained in the server.