Subject | RE: [firebird-support] Re: Auto Incrementing field |
---|---|
Author | Richard Pendered |
Post date | 2003-12-09T16:25:20Z |
Here is some SQL DDL for a generator and trigger to do auto increment
columns.
CREATE GENERATOR gen_fl_id;
/* Table: FAVOURITE_LIST */
SET SQL DIALECT 3;
SET NAMES NONE;
/***************************************************************************
***/
/* Tables
*/
/***************************************************************************
***/
CREATE TABLE FAVOURITE_LIST (
FL_ID INTEGER NOT NULL,
FL_USERNAME VARCHAR(30) NOT NULL,
FL_NAME VARCHAR(80) NOT NULL,
FL_PASSWORD VARCHAR(20) NOT NULL,
FL_EMAIL VARCHAR(128),
FL_PRODUCT INTEGER NOT NULL,
FL_FF_ID INTEGER,
FL_DELETED SMALLINT default '0' NOT NULL
);
/***************************************************************************
***/
/* Primary Keys
*/
/***************************************************************************
***/
ALTER TABLE FAVOURITE_LIST ADD CONSTRAINT PK_FAVOURITE_LIST PRIMARY KEY
(FL_ID);
/***************************************************************************
***/
/* Foreign Keys
*/
/***************************************************************************
***/
ALTER TABLE FAVOURITE_LIST ADD CONSTRAINT FK_FAVOURITE_LIST FOREIGN KEY
(FL_FF_ID) REFERENCES FAVOURITE_FOLDER (FF_ID);
/***************************************************************************
***/
/* Triggers
*/
/***************************************************************************
***/
SET TERM ^ ;
/* Trigger: TG_FAVOURITE_LIST_ID */
CREATE TRIGGER TG_FAVOURITE_LIST_ID FOR FAVOURITE_LIST
ACTIVE BEFORE INSERT POSITION 0
AS
begin
new.fl_id = gen_id( gen_fl_id, 1 );
end
^
SET TERM ; ^
-----Original Message-----
From: benmarron [mailto:colletb@...]
Sent: 09 December 2003 15:47
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Re: Auto Incrementing field
--- In firebird-support@yahoogroups.com, Bahadir ARMAGAN
<barmagan@t...> wrote:
The general method to get unique autoicremented value is : generator +
trigger to get generator value and increment it when new record is
inserted.
To unsubscribe from this group, send an email to:
firebird-support-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
columns.
CREATE GENERATOR gen_fl_id;
/* Table: FAVOURITE_LIST */
SET SQL DIALECT 3;
SET NAMES NONE;
/***************************************************************************
***/
/* Tables
*/
/***************************************************************************
***/
CREATE TABLE FAVOURITE_LIST (
FL_ID INTEGER NOT NULL,
FL_USERNAME VARCHAR(30) NOT NULL,
FL_NAME VARCHAR(80) NOT NULL,
FL_PASSWORD VARCHAR(20) NOT NULL,
FL_EMAIL VARCHAR(128),
FL_PRODUCT INTEGER NOT NULL,
FL_FF_ID INTEGER,
FL_DELETED SMALLINT default '0' NOT NULL
);
/***************************************************************************
***/
/* Primary Keys
*/
/***************************************************************************
***/
ALTER TABLE FAVOURITE_LIST ADD CONSTRAINT PK_FAVOURITE_LIST PRIMARY KEY
(FL_ID);
/***************************************************************************
***/
/* Foreign Keys
*/
/***************************************************************************
***/
ALTER TABLE FAVOURITE_LIST ADD CONSTRAINT FK_FAVOURITE_LIST FOREIGN KEY
(FL_FF_ID) REFERENCES FAVOURITE_FOLDER (FF_ID);
/***************************************************************************
***/
/* Triggers
*/
/***************************************************************************
***/
SET TERM ^ ;
/* Trigger: TG_FAVOURITE_LIST_ID */
CREATE TRIGGER TG_FAVOURITE_LIST_ID FOR FAVOURITE_LIST
ACTIVE BEFORE INSERT POSITION 0
AS
begin
new.fl_id = gen_id( gen_fl_id, 1 );
end
^
SET TERM ; ^
-----Original Message-----
From: benmarron [mailto:colletb@...]
Sent: 09 December 2003 15:47
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Re: Auto Incrementing field
--- In firebird-support@yahoogroups.com, Bahadir ARMAGAN
<barmagan@t...> wrote:
> I have an integer field that an application increments it each timeit adds
> a record. But when I run the intances of that application at thesame time ,
> I get an error because all the instances reading the same last value andThere is no autoincrement field in Firebird.
> trying to insert the same incremented value to this unique field.
>
> What is the general methode that is to be followed for this problem?
> Is it possible to create an autoincrement field as in access databases?
> What if I try to make a field (already have unique recodrs in it)
> autoincrement?
>
The general method to get unique autoicremented value is : generator +
trigger to get generator value and increment it when new record is
inserted.
To unsubscribe from this group, send an email to:
firebird-support-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/