Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: Auto Increment Primary key?

Re: Auto Increment Primary key?

From: <rspeaker_at_my-deja.com>
Date: 1999/12/21
Message-ID: <83o40t$qhe$1@nnrp1.deja.com>#1/1

you can use the CREATE SEQUENCE command to create a sequence. Once created, you can reference the pseudo-columns NEXTVAL and CURRVAL in your select/insert statements. Then, make your sequence column the PK for the table. For example, to insert a record using the next available number you would do something like INSERT INTO TABLE T VALUES (sequence.NEXTVAL, val2, val3, ...);

Keep in mind that dropped values in the sequence do not automatically get reassigned so you may have holes in your sequence. There are additional parameters to the CREATE SEQUENCE command to handle things such as the starting value, the increment value, the max value, and whether or not to recycle the sequence when you reach the max value.

HTH,
Roy

In article
<Pine.LNX.4.10.9912171604300.29563-100000_at_alfred.laffeycomputer.com>,   John Shaft <shaft_at_meanmutha.com> wrote:
> Hi,
>
> Does Oracle has a way to define a table such that the primary key gets
> auto-incremented with each new insertion? If not, how do you keep your
> primary keys unique? (With a store value read and incremented in a
> transaction?)
>
> I have a databse devloped orignally for MySQL and want to port it to
> Oracle 8. I wondered about this issue.
>
> Thanks!
>
> shaft_at_meanmutha.com
> http://www.meanmutha.com
>
>

Sent via Deja.com http://www.deja.com/
Before you buy. Received on Tue Dec 21 1999 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US