Re: how to know the next serial id
Posted in 2004
Topics: Server Administration
vk02720 wrote:
> How do I know the next value that is going to be in a serial id column
> before I do an insert ? select max(my_id) may not work because the
> rows get constantly deleted as well.
> Is there any way in dbaccess to view the next id as well ?
No-one can tell what number will be allocated to your insertion
because it is a multi-user system and who gets which number depends on
who inserts which rows when. Note that the 'no-one' in question
includes the DBMS -- it knows which number will be allocated to the
next request, but it does not know who is going to make the next request.
--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/
Jonathan Leffler wrote:
> vk02720 wrote:
>
>> How do I know the next value that is going to be in a serial id column
>> before I do an insert ? select max(my_id) may not work because the
>> rows get constantly deleted as well.
>> Is there any way in dbaccess to view the next id as well ?
>
>
> No-one can tell what number will be allocated to your insertion because
> it is a multi-user system and who gets which number depends on who
> inserts which rows when. Note that the 'no-one' in question includes
> the DBMS -- it knows which number will be allocated to the next request,
> but it does not know who is going to make the next request.
Just out of curiosity, why do you want to know what the next value will
be *prior* to the insertion? Why won't the standard methods of
retrieving the value of the serial *after* the insertion (reviewing the
value in the sqlca record or calling the dbinfo function) work for you?
--
June Hunt