Help with self-incremental fields

David

Member
I am new in client/server databases, so please have patience with my dumb
questions.
smile.gif


I am writing an application using D6+Direct Oracle Access+Oracle 8i. So far,
everything is easy.

I am using numeric ID fields for identifying records in each table. Example:
ALUMN_ID, TEACHER_ID, etc.

The problem is that I want to use a self-incremental numeric field, so
automatically each new record is given a new ID. And I have no clue about
how to do it, I couldn't find anything in oracle or DOA documentation.
 
In Oracle you would use a sequence to produce an incrementing value.

To achieve an autoincrement field you would use an insert trigger on the table that gets the next value from the sequence.

e.g.
CREATE SEQUENCE table1_id_seq START WITH 1;
CREATE TRIGGER table1_ins BEFORE INSERT ON table1 FOR EACH ROW
DECLARE
NewID INTEGER;
BEGIN
SELECT table1_id_seq.nextval INTO NewID FROM dual;
:new.ID := NewID;
END;
 
Hi David,

it might even be easier. Sure you need a sequence like explained by jpickup. But the trigger is not a must. Just use TOracleDataSet.SequenceField and the work is done for you by ODA!
 
Back
Top