Subject | Re: [ib-support] Immediately get auto generated key |
---|---|
Author | Meta Nurwidyanto |
Post date | 2003-02-25T03:10:03Z |
On Sunday 09 February 2003 21:01, Arno Brinkman wrote:
create trigger "session_tgr" for "plansessions"
active before insert position 0
as
begin
new.session_id=gen_id(session_gen,1);
end;
It' assumed u already had session_gen as generator.
--m
> Hi,This is more simple, in fact, I use it to do autonumber with any field ID:
>
> > Is it possible in one Stored Procedure to get the auto generated key
> > for a row?
>
> I guess you use an generator in the trigger and check if SESSION_ID IS
> NULL.
>
> > begin
> > INSERT INTO PLANSESSIONS ( SESSION_INFO )
> > VALUES ( :SESSIONINFO );
> > suspend;
> > end
> >
> > But would like to get directly the autogenerated key 'SESSION_ID'.
> > How can I do this?
>
> Generate first the ID in the SP and use that as input value inside your
> INSERT.
>
> DECLARE VARIABLE ID INTEGER;
> BEGIN
> ID = GEN_ID("GEN_SESSION_ID",1);
> INSERT INTO
> PLANSESSIONS (SESSION_ID, SESSION_INFO )
> VALUES (:ID, :SESSIONINFO);
> SUSPEND;
> END
>
> Regards,
> Arno
create trigger "session_tgr" for "plansessions"
active before insert position 0
as
begin
new.session_id=gen_id(session_gen,1);
end;
It' assumed u already had session_gen as generator.
--m