Re: SQL question (Autoincrementing value.)

From: Thomas Tuft Muller <ttm_at_online.no>
Date: 2000/01/31
Message-ID: <V_ll4.18764$in5.329168_at_news1.online.no>#1/1


Ron Stow wrote in message <86vd6a$je$1_at_neptunium.btinternet.com>...
>I am access a database for a Workflow system that records a historic list
 of
>events on 'Work Ojcects' in a History table, the problem is the system only
>stores the 'After Image' and a lot of the results we whant require
>specifying criteria if the before and after the event has taken place. To
>match records in SQL it would be easier if they where incrementing field
>value that I could join using (b.ID = a.ID+1)
>
>***How do I insert an incrementing field value in an new table?***
>
[cut]

Generating unique Integer IDs is not an innate part of SQL, consequently each vendor has it's own way of generating such. Oracle uses an object called a sequence which guarantee to deliver a unique ID irrespective of simultanious enquiries. This object could be interrogated in a BEFORE INSERT trigger to get the unieue ID, or the inserter could get it himself with a SELECT <seq-name>.nextval FROM DUAL. You should consult the documentation on your particular DBMS regarding sequence-like features.

--

Thomas
Received on Mon Jan 31 2000 - 00:00:00 CET

Original text of this message