Subject Re: [firebird-support] Re: max() on primary key very slow
Author Mark Rotteveel
On 11-2-2012 18:05, Kjell Rilbe wrote:
> Enter one row in this table for each table you need a PK "generator"
> for. To aquire a key, start your transaction with:
>
> update "PK"
> set "LastUsedId" = "LastUsedId" + 1
> where "TableName" = :TableName
>
> Then
>
> select "LastUsedId"
> from "PK"
> where "TableName" = :TableName

You could UPDATE .... RETURNING "LastUsedId" (or explicitly
NEW."LastUsedId") to get it in one go.

--
Mark Rotteveel