Get last insert ID from Access

I am familiar with the MySQL function LAST_INSERT_ID; is there a similar function to execute the same query with the MS Access database via ODBC?

In my particular case, I use PHP + PDO to insert rows into the Access database and would like to know the last primary key value for each insert when they are executed.

If this feature is not available, are there any alternatives? (without changing the database)

Thank.

+3
source share
4 answers

Access 2000 or later seems to support the property @@IDENTITY. Thus, you will need to select its value after INSERT:

select @@IDENTITY from myTable

. MSDN: Retrieving Identity or Autonumber Values

:

[...] Microsoft Access 2000 @@IDENTITY Autonumber INSERT. RowUpdated, , INSERT, @@IDENTITY DataSet.

+5

, SELECT @@IDENTITY Jet 4 ACE.

Access 2010 , , ACE , . , , @@IDENTITY . , SQL Server SCOPE_IDENTITY().

Access, , , . , , ACCDB .

+2

php, : . max (id) , , , . -, odbc_cursor (http://au2.php.net/manual/en/function.odbc-cursor.php).

+1
source

Try running "SELECT @@ IDENTITY FROM MyTable" after your insert.

+1
source

Source: https://habr.com/ru/post/1773873/


All Articles