Subject Re: [firebird-support] SELECT MAX
Author Doug Chamberlin
Bud Millwood wrote:
>> Why do you want to get the max number?
>
> It's a generated id. When the app starts we want the largest one, and we keep
> incrementing for new records.

Another way to handle this is to place triggers on the table which
updates a field in another table that is defined to be the max value.
That way you only have to query the other table's one record to get the
current max value.

I hope you are aware of the many ways that maintaining a max value this
way can go wrong and have planned on handling them. For example, in the
time it takes to obtain the current max value, increment it, and post a
new record with the calculated value, another user could have completed
the same sequence and therefore produced a collision of values.