Re: SELECTing the last value inserted into a SERIAL column
Posted in 1997
Clay,
The sqlca record carries the status information for the last SQL processed
by YOUR program. Other inserts into the table do not affect this record.
If you run the following query as the next statement after processing
an insert you will get YOUR serial value:
SELECT DBINFO('sqlca.sqlerrd1') FROM SYSTABLES WHERE TABID = 99
This is true even if there are other inserts to the table by other programs
before you query the sqlca record.
I tested this in dbaccess by running two sessions and doing two inserts,
then checking
sqlca. Try it yourself and see!!
Hope this helps,
Bruce Farwell
Spartan Stores, Inc.
Grand Rapids, MI
>Others suggested using the dbinfo function to retrieve the last value.
>However, couldn't another insert into that column cause you to retrieve
>the incorrect value? Is there anyway to apply a lock so another insert
cannot happen?