----- Original Message -----
From: "Frank Ingermann" <frank.ingermann@...>
To: <ib-support@yahoogroups.com>
Sent: Tuesday, June 12, 2001 9:36 PM
Subject: Re: [ib-support] ato increment / IDENTITY
> there is not a single command in IB that will do this, but maybe this helps:
>
> a) define the table with a suitable field for the primary key:
> CREATE TABLE TTEST ( ID Integer, <other fields> );
>
> b) define the primary key column:
> ALTER TABLE TTEST ADD CONSTRAINT PK_TTEST PRIMARY KEY ( ID );
> (note this will implicitly build a unique index on ID)
>
> c) define the Generator (a "server-side variable" that will store the
> current auto-inc value in a multi-user-safe way):
> CREATE GENERATOR GEN_ID_TTEST;
>
> d) build a trigger that fires before the record gets inserted and
> fills the ID column with the next generator value:
>
> SET TERM ^;
>
> CREATE TRIGGER TRG_ID_TTEST FOR TTEST
> ACTIVE BEFORE INSERT POSITION 0 AS
> BEGIN
> if ((NEW.ID=0) or (NEW.ID IS NULL)) then /* if it's not already there... */
> NEW.ID = GEN_ID(GEN_ID_TTEST, 1); /* ...get the next value */
> END
> ^
>
Hi,
that was right what I was looking for, now I understand.
The value to increase in the created GENERATOR. The GENERATOR is only used in one trigger and therefore stores the right value (minus one) to insert.
Do I see right? NEW is the keyword that names the new record (to insert)?