Subject | Re: [Firebird-Java] Create auto-increment primary key? |
---|---|
Author | Helen Borrie |
Post date | 2004-06-08T05:05:10Z |
At 04:51 AM 8/06/2004 +0000, you wrote:
support it with a Before Insert trigger on the table.
create generator gen_mytablePK;
create trigger bi_mytable for mytable
active before insert
as
begin
if (new.PK is null) then
new.PK = GEN_ID(gen_mytablePK, 1);
end
Generators never roll back and, unlike auto-inc types, you can pull a
generator value at any time. That means your application can know the new
PK value before you create the row - v. useful for master-detail
structures. This is how you get the value:
select GEN_ID(gen_mytablePK, 1) from rdb$database;
Try to ask SQL questions in Firebird-support, please. They're off-topic here.
Helen
(resident ^witch)
>Hi, I have a script which I run to create my database. Is there a wayNo. Firebird doesn't have an auto-increment type. Use a generator and
>(using standard SQL) to specify that a PK is an auto-increment column?
>(I.e I understand AUTO_INCREMENT is a MySQL extension and non-standard).
support it with a Before Insert trigger on the table.
create generator gen_mytablePK;
create trigger bi_mytable for mytable
active before insert
as
begin
if (new.PK is null) then
new.PK = GEN_ID(gen_mytablePK, 1);
end
Generators never roll back and, unlike auto-inc types, you can pull a
generator value at any time. That means your application can know the new
PK value before you create the row - v. useful for master-detail
structures. This is how you get the value:
select GEN_ID(gen_mytablePK, 1) from rdb$database;
Try to ask SQL questions in Firebird-support, please. They're off-topic here.
Helen
(resident ^witch)