Subject Re: [firebird-support] Can I set a GENERATOR value using SELECT ?
Author The Wogster
Graeme Edwards wrote:
>> Hi,
>
>> I am trying to set some generator values using a SELECT MAX(ID) FROM
>> MYTABLE?
>> Can this be done? or some automatic way for this?
>
>> I was thinking of some code like this:
>> SET GENERATOR GEN_MY_TABLE_ID TO SELECT MAX(ID) FROM MYTABLE
>
> I'm making no comment on the advisability of doing this, but I have had
>
> to do similar things when adding a new generator to an existing table.
>
> One thing I have tried is
>
> Set Generator to 0
>
> Select Gen_ID(GEN_Name,(Select max(ID) from TABLE)) from rdb$Database
>
> The select statement forces the update of the generator value by Max(ID)
>
> from table. RDB$Database is used because it has one record and I only
>
> want to increment the generator once by max(ID)
>
> Graeme
>

I suggest adding a buffer value, say round UP to the next 1,000,000 this
will give you a definite starting point for the generator values, versus
the previous values. It also means that if the old method of adding new
records doesn't get disabled right away, that you don't get duplicate
values.

W