Creating primary key values with trigger
From: Pedro Pimentel <ppf_at_fct.unl.pt>
Date: Wed, 7 Sep 1994 23:17:16 GMT
Message-ID: <1994Sep7.231716.3493_at_fct.unl.pt>
....
) ;
Date: Wed, 7 Sep 1994 23:17:16 GMT
Message-ID: <1994Sep7.231716.3493_at_fct.unl.pt>
I think it would be nice if oracle could create primary key values automagically (like 'counter' fields in MS Access). I was thinking about something like this:
create table myTable (
ID number(5) CONSTRAINT pk_myTable PRIMARY KEY, field1 char(30),
....
) ;
create sequence seq_myTable ;
create or replace trigger check_myTable
before insert
on myTable
for each row
begin
:new.ID := seq_myTable.nextval ;
end ;
This doesn't work because Oracle checks for null values in the ID field before running the trigger.
-- Pedro Pimentel e-mail: ppf_at_fct.unl.pt www: http://ester.fct.unl.pt/pedro1.htmReceived on Thu Sep 08 1994 - 01:17:16 CEST