3

Anyone knows how to retrieve a new AutoInc that gets written after an ODBC INSERT? Is there a variable I have access to just like SQL Server? Right now, I'm using :

SELECT MAX(myautoincfield) AS mylastkey FROM anytable 

in order to retrieve my new key.

2 Answers 2

4

The scalar function LastAutoinc can retrieve it efficiently:

select LastAutoinc(statement) as mylastkey from system.iota;
0

The global variable @@identity identifies the last value inserted into an IDENTITY column by the current session.

You may do the following:

select @@identity

in order to retrieve the new key.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.