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: how to set the column be auto increment no.??

Re: how to set the column be auto increment no.??

From: andrewst <member14183_at_dbforums.com>
Date: Fri, 04 Jul 2003 11:16:41 +0000
Message-ID: <3075001.1057317401@dbforums.com>

Originally posted by Myhome
> I want to create a table with a field called "seqno" that is a auto
> increment number. What is the stynax of setting auto increment??
>
> Now, I create my table temporily by this statement:
> create table AAA (seqno number(10) not null)
>
> thx

There is no auto-incrementing column in Oracle like there is in SQL Server. Instead, create a sequence like this:

CREATE SEQUENCE myseq;

Then when inserting values you can do this:

INSERT INTO aaa (seqno) VALUES (myseq.NEXTVAL)

Alternatively you could create a BEFORE INSERT trigger on the table to get myseq.NEXTVAL so that the insert statement doesn't have to include seqno.

--
Posted via http://dbforums.com
Received on Fri Jul 04 2003 - 06:16:41 CDT

Original text of this message

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