Subject Re: Can I set a GENERATOR value using SELECT ?
Author Adam
--- In firebird-support@yahoogroups.com, "Graeme Edwards"
<g.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,

I will.

Do not even think about doing this unless you are the only user
connected at the time. Otherwise you risk setting the generator to
the wrong record. This will mean shutting down the database or
renaming it to be sure.

> 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

Clever way of doing it though. I have seen a SP before that resets
all generators to the max of each table (requires the generator name
to be calculated from the table name) which is another way with the
same risks.

Adam