Subject | RE: [ib-support] ato increment / IDENTITY |
---|---|
Author | Thomas Steinmaurer |
Post date | 2001-06-13T08:16:32Z |
Bernhard,
generators store unique numbers database wide. Each time you call
GEN_ID(generator, 1) your generator is increased by 1. But be aware that
generators are running outside a transaction context and will be therefore
not decreased when you rollback your transaction.
Thomas
generators store unique numbers database wide. Each time you call
GEN_ID(generator, 1) your generator is increased by 1. But be aware that
generators are running outside a transaction context and will be therefore
not decreased when you rollback your transaction.
Thomas
> -----Original Message-----
> From: Bernhard Doebler [mailto:programmer@...]
> Sent: Wednesday, June 13, 2001 10:00 AM
> To: ib-support@yahoogroups.com
> Subject: Re: [ib-support] ato increment / IDENTITY
>
>
>
> ----- 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)?
>
> Best regards and thanks alot
> Bernhard
>
>
> To unsubscribe from this group, send an email to:
> ib-support-unsubscribe@egroups.com
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>