Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Clarification of 'Sequences'
On Wed, 30 Sep 1998 10:08:18 -0400, "steve hendrikse" <shend_at_sar-net.com> wrote:
>Good Day,
>
>I have reasonable experience with both PostgreSQL and Micrsoft SQLServer.
>WIth both I can create a column in a table that automatically generates a
>unique count value. That is:
>
>in MSSQL, i do:
> create tabel test1(
> id int identity(1,1) not null,
> value varchar(80)
> );
>
>in PostgreSQL, it is slightly more complex, but similar to:
>
> create sequence seq_id start 1 increment 1;
> create table test2(
> id int4 default nextval('seq_id') not null,
> value varchar(80)
> );
>
>now, in Oracle 8.0.4 (on Solaris), i believe that i must do something
>similar to the PostgreSQL case. I start with:
>
> create sequence seq_id start with 1 increment by 1;
>
>and then (?????)
>
> create table
>
> id int default seq_id.nextval not null,
> value varchar(80)
> );
>
>but this gets me an error saying that i cannot include a column name
>(seq_id) in the table definition.
>
>now, i conclude that if both MSSQL and PostgreSQL can do this (as shown
>above) there has to be a 'graceful' way to get Oracle to do it also.
>
>please help!!!
>
>thanks in advance,
>steve
>
Unfortunately, when you're creating a table in Oracle, you can't define a column to be of auto-incrementing type. The column must be defined the normal way and the sequence used whenever a record is inserted. E.g.:
insert into table (id,value) values (seq_id.nextval,1);
Good luck,
Nuno Guerreiro
As I don't normally appreciate unsolicited commercial e-mail (widely known as SPAM), I encoded my e-mail address. If you want to reply by e-mail, please remove the text added to fool spam software
"The art of arts, the glory of expression and the sunshine that lights the light of letters is simplicity"
Walt Whitman Received on Wed Sep 30 1998 - 00:00:00 CDT
![]() |
![]() |