Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> Re: Assign unique primary key for new rows
In article <3934249D.F8E4BA1E_at_mediashell.net>,
leenick_at_bigfoot.com wrote:
> Hi,
>
> Another newbie question ...
>
> Is there any way I can get Oracle to automatically assign a unique
> value to one of the columns for every new rows that I add? That column
> can, in turn, be the primary key of the table.
>
> Any help is greatly appreciated,
> EN
>
Hi
Yes, with a sequence
CREATE SEQUENCE my_sequence
INCREMENT BY some_number(1 for example)
START WITH some_number
NOCYCLE;
To insert this value
INSERT INTO my_table (ID, other cols, etc)
VALUES (my_sequence.NEXTVAL, other cols, etc)
Hth
Sanrenkur
Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Tue May 30 2000 - 00:00:00 CDT