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: Sequences and Primary Keys

Re: Sequences and Primary Keys

From: Sybrand Bakker <postbus_at_sybrandb.demon.nl>
Date: Sun, 15 Apr 2001 12:57:48 +0200
Message-ID: <tdivhhaf061gf4@beta-news.demon.nl>

<safbaf> wrote in message news:3ad93973.734296_at_news.freeuk.net...
> Hi,
>
> I want to set up a sequence which can then be used as a primary key in
> a feild.
> EG: setup sequence called pnum, then have a feild called pnum in my
> table, pnum being primary key and referenced by other tables.
> Sorry if this question is a bit lame, I`ve only just started with
> Oracle (their documentation assumes a level of knowledge I dont yet
> have)
> Thanks
>

So
create sequence pnum_seq start with 1 increment by 1 etc.
(optional:
grant select on pnum_seq to <any user having insert access to the table>; create public synonym pnum_seq for pnum_seq; )

And

create or replace trigger foo_bifer before insert on foo for each row is begin
select pnum.nextval
into :new.pnum
from dual;
end;
/

And you should be set.

You can best start with Oracle Concepts Manual, and the Oracle Application Developers Manual.

Hth,

Sybrand Bakker, Oracle DBA Received on Sun Apr 15 2001 - 05:57:48 CDT

Original text of this message

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