Subject | Info |
---|---|
Author | Рустам Муса-Ахунов |
Post date | 2017-12-20T09:07:20Z |
As I answer you on your first time question - use this query to get next ID. Then supply this ID in your next INSERT query.
select
gen_id(GEN_TABLENAME, 1)
from RDB$DATABASE
CREATE GENERATOR GEN_TABLENAME;
SET TERM ^ ;
CREATE OR ALTER TRIGGER TABLENAME_BI FOR TABLENAME
ACTIVE BEFORE INSERT POSITION 0
AS
begin
if (new.ID is null) then new.ID = gen_id(GEN_TABLENAME, 1);
end
^
SET TERM ; ^
select
gen_id(GEN_TABLENAME, 1)
from RDB$DATABASE
Where GEN_TABLENAME - generator for your A.ID column. In this case you not need to declare you column as IDENTITY. Instead create GENERATOR and BEFORE INSERT trigger like this:
CREATE GENERATOR GEN_TABLENAME;
SET TERM ^ ;
CREATE OR ALTER TRIGGER TABLENAME_BI FOR TABLENAME
ACTIVE BEFORE INSERT POSITION 0
AS
begin
if (new.ID is null) then new.ID = gen_id(GEN_TABLENAME, 1);
end
^
SET TERM ; ^