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: Jim Kennedy <kennedy-family_at_home.com>
Date: Tue, 06 Nov 2001 06:09:50 GMT
Message-ID: <O8LF7.24985$Tb.13778294@news1.sttln1.wa.home.com>


Ron is correct. Also Max means it has to issue a sql statement just to do the insert. More performance hit, etc.
Jim
"Ron Reidy" <rereidy_at_indra.com> wrote in message news:3BE77176.EC9F3D5D_at_indra.com...
> Nicholas Carey wrote:
> >
> > 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).
> > --
> Yes, TMTOWTDI, but the way above with the SQL statement will not always
> result in a new unique value. Consider using a PRE-INSERT trigger along
> with a sequence for the table - see the PL/SQL user's guide. This will
> guarantee unique values.
> --
> Ron Reidy
> Oracle DBA
> Reidy Consulting, L.L.C.
Received on Tue Nov 06 2001 - 00:09:50 CST

Original text of this message

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