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: Autoincrement field

Re: Autoincrement field

From: Richard J Woodland <richwoodland_at_interfacefamily.com>
Date: 2000/05/31
Message-ID: <3935120e$0$40278@news.voyager.net>#1/1

The 'normal' method would be to create an Oracle sequence, then use it to assign unique key values. For example :-

CREATE TABLE elements (id NUMBER NOT NULL,name VARCHAR2(100)); CREATE SEQUENCE element_seq INCREMENT BY 1 START WITH 1; INSERT INTO elements(id,name) VALUES(element_seq.NEXTVAL,'Hydrogen'); INSERT INTO elements(id,name) VALUES(element_seq.NEXTVAL,'Helium'); COMMIT; SELECT * FROM elements;

ID     NAME
--     --------
1      Hydrogen
2      Helium

If you really want, add an insert trigger on the table, and have it automatically assign a unique key (using the sequence) during the insert operation.

Hope this helps.

Rich Woodland
Magic Interface, Ltd.

Echoes wrote:

> Hello,
>
> I'm new at Oracle usage, and i'm looking for
> something i used with mysql:
>
> I have a number field in a table, and I want it to be
> incremented for each new insertion, making it a unique
> key for this table. With mysql I just have to specify
> an AUTO_INCREMENT option for the field, but with Oracle ?
>
> Thanks
>
> Eugene
Received on Wed May 31 2000 - 00:00:00 CDT

Original text of this message

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