Subject RE: [firebird-support] Re: Auto Incrementing field
Author Helen Borrie
At 10:28 AM 10/12/2003 +0200, you wrote:
>Thank you for your explanation. I did it.
>Now how can I get this auto generated vaule when I insert records? I have an
>example for mssql server which uses @@IDENTITY for returning this value.
>Does it work for firebird?

That's MSSQL server, this is Firebird.

Beware!
select gen_id(gen_your_id, 0) from rdb$database will give the latest value,
but it's not necessarily the value you just generated. (Someone else might
have been along and got another one).

If you need to *know* the generated value in your app, get it *before* you
insert the new row, using
select gen_id(gen_your_id, 1) from rdb$database

And make sure your trigger is

IF (NEW.YOUR_ID IS NOT NULL) THEN
NEW.YOUR_ID = GEN_ID(GEN_YOUR_ID, 1);

/h