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: <safbaf>
Date: Mon, 16 Apr 2001 05:48:59 GMT
Message-ID: <3ada87c9.887500@news.freeuk.net>

On Sun, 15 Apr 2001 12:57:48 +0200, "Sybrand Bakker" <postbus_at_sybrandb.demon.nl> wrote:

Hi and thanks for the answer, but another question - whats all this foo_bifer stuff. (I understand a bit about the concept of triggers)

Safbaf

>
><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 Mon Apr 16 2001 - 00:48:59 CDT

Original text of this message

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