I am familiar with the MySQL function LAST_INSERT_ID; is there a similar function for performing the same query with a MS Access database via ODBC?
In my specific case, I am using PHP+PDO to insert rows into an Access database, and would like to know the last primary key value of each insert as they are performed.
If this functionality is not available, are there any alternatives? (without changing the database)
Thank you.
It seems that Access 2000 or later supports the @@IDENTITY property. So, you would only need to select its value after an INSERT:
select @@IDENTITY from myTable
Please see the MSDN link: Retrieving Identity or Autonumber Values
In short:
[...] Microsoft Access 2000 or later does support the @@IDENTITY property to retrieve the value of an Autonumber field after an INSERT. Using the RowUpdated event, you can determine if an INSERT has occurred, retrieve the latest @@IDENTITY value, and place that in the identity column of the local table in the DataSet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With