Subject | RE: [firebird-support] Re: Auto Incrementing field |
---|---|
Author | Helen Borrie |
Post date | 2003-12-10T09:12:37Z |
At 10:28 AM 10/12/2003 +0200, you wrote:
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
>Thank you for your explanation. I did it.That's MSSQL server, this is Firebird.
>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?
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