Subject | Re: Sequential auto incremental numbering |
---|---|
Author | |
Post date | 2018-09-02T22:19:01Z |
Hi Christian...
I use Firebird Generators for primary-key generation and they work fine...
Here is the generated Firebird-PSQL for a table in my current project development, which uses a generator to create a primary-key number upon insertion...
>>>
CREATE TABLE RI_DOCUMENT_STORAGE (
DS_KEY BIGINT NOT NULL,
DS_DOCUMENT_MASTER_KEY BIGINT NOT NULL,
DS_DOCUMENT BLOB NOT NULL);
SET TERM ^ ;
CREATE TRIGGER BI_RI_DOCUMENT_STORAGE_DS_KEY FOR RI_DOCUMENT_STORAGE
ACTIVE BEFORE
INSERT
POSITION 0
AS
BEGIN
IF (NEW.DS_KEY IS NULL) THEN
NEW.DS_KEY = GEN_ID(RI_DOCUMENT_STORAGE_DS_KEY_GEN, 1);
END^
SET TERM ; ^
DS_KEY BIGINT NOT NULL,
DS_DOCUMENT_MASTER_KEY BIGINT NOT NULL,
DS_DOCUMENT BLOB NOT NULL);
SET TERM ^ ;
CREATE TRIGGER BI_RI_DOCUMENT_STORAGE_DS_KEY FOR RI_DOCUMENT_STORAGE
ACTIVE BEFORE
INSERT
POSITION 0
AS
BEGIN
IF (NEW.DS_KEY IS NULL) THEN
NEW.DS_KEY = GEN_ID(RI_DOCUMENT_STORAGE_DS_KEY_GEN, 1);
END^
SET TERM ; ^
<<<
A good database manager for Firebird will do this for you...
Steve Naidamast
Sr. Software Engineer