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

Home -> Community -> Usenet -> c.d.o.misc -> Re: Such a thing as auto increment in oracle?

Re: Such a thing as auto increment in oracle?

From: Nicholas Carey <ncarey_at_speakeasy.org>
Date: Tue, 06 Nov 2001 04:50:53 -0000
Message-ID: <Xns9150D4142DFD4ncareyspeakeasyorg@207.126.101.92>


On 05 Nov 2001, Sybrand Bakker <postbus_at_sybrandb.demon.nl> spake and said:

> On Mon, 05 Nov 2001 21:48:18 +1100, Chris Newman
> <chris_newman_at_bigpond.com> wrote:
>

>>I am using Oracle version 7 for Windows 95 and want to
>>increment values in a column one at a time starting with 1,
>>2, 3 etc to serve as a primary key. MySQL calls this feature
>>auto-increment. How do I do this please 

>
> In Oracle you can create auto increment number as an object
> called 'sequence'.
>
> First create a sequence,
>
> SQL> create sequence my_seq;
>
> ...

Or you can do it in the more 'relationally correct' way:

  create table foo
  ( id int not null primary key ,     col_1 varchar2(64) not null
  )

  insert into foo ( id , col_1 )

  select max(id)+1         id    ,
         'you-value-here'  col_1

  from foo

As they say in the land of Perl, "TMTOWTDI" (There's more than one way to do it).

-- 
Received on Mon Nov 05 2001 - 22:50:53 CST

Original text of this message

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