Subject Re: [ib-support] Setting a generator to the maximum value of the primary key
Author Stevio
Thanks Luc.

The following code, modified from what you gave me, does what I am looking
for fine:
SELECT GEN_ID(GEN_NEW_AUTHOR_ID, (SELECT MAX (AUTHOR_ID) FROM AUTHOR)) FROM
RDB$DATABASE

I don't need to add 1 to it, as I understand, because the first time the
code is used it will give me the next value, not the current value, for the
new record being added. If this is wrong please tell me.

Also, I tried this code without the SELECT .... FROM RDB$DATABASE parts code
and it didn't work. Why do I need this "select from" round the generator
code?

Thanks again,
Stephen


> > Can someone tell me how to fix the following code please?
> >
> > SET GENERATOR GEN_NEW_AUTHOR_ID TO (SELECT MAX(AUTHOR_ID) FROM AUTHOR);
>
> you might try:
>
> SELECT GEN_ID ( GEN_NEW_AUTHOR_ID,
> ( SELECT MAX ( AUTHOR_ID ) FROM AUTHOR ) + 1 )
> FROM RDB$DATABASE
> (this is if the current genvalue is 0)