At the moment my application uses an Oracle db and I am really happy about it. My intention is to implement the same app with Derby (just to make it more portable). With Oracle I use a trigger with 'BEFORE INSERT' and a sequence and it works ok. I would like to implement the same with Derby, but it seams impossible. I also found this article: Sequences and Triggers in Derby DB Is the content of the article correct ? Why Derby does not have such a common feature implemented ?
Thanks Alb
This is what I used in oracle:
CREATE TABLE "SITES"
("SITE_ID" NUMBER NOT NULL ENABLE,
"SITE_NAME" VARCHAR2(100) NOT NULL ENABLE,
"SITE_LINK" VARCHAR2(500) NOT NULL ENABLE,
"SITE_DESC" VARCHAR2(100) NOT NULL ENABLE,
"SITE_DATA_IN" DATE,
CONSTRAINT "SITE_PK" PRIMARY KEY ("SITE_ID") ENABLE
)
CREATE OR REPLACE TRIGGER "SITES_TRIGGER"
before insert on SITES
for each row
begin
select SITES_SEQ.nextval into :new.SITE_ID from dual;
end;
/
ALTER TRIGGER "SITES_TRIGGER" ENABLE
/
CREATE SEQUENCE "SITES_SEQ" MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 301 CACHE 20 NOORDER NOCYCLE