Subject Re: [firebird-support] SELECT MAX() or Generator
Author Ann W. Harrison
William L. Thomson Jr. wrote:
>
> DECLARE VARIABLE max_num INTEGER;
> BEGIN
> IF(new.NUM is NULL)
> THEN
> BEGIN
> SELECT MAX(NUM) FROM MY_TABLE INTO max_num;
> new.NUM = max_num+1;
> END
> END
>
> I have been doing this for quite some time.

There are two problems with this. The first is performance, which can
be addressed by putting a descending index on NUM. The second is that
it flat doesn't work multi-user, which may or may not be important to
you. If you absolutely must have sequential numbers, follow Alexandre
Benson Smith's suggestion, but be aware that any mechanism that produces
reliably sequential numbers will serialize updates.

Regards,


Ann