Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: HELP: Sequences and primary keys beginner question.

Re: HELP: Sequences and primary keys beginner question.

From: Ben Harmon <benh_at_dascom.com>
Date: 1997/06/24
Message-ID: <5op36e$9an@news9.noc.netcom.net>#1/1

Thanks Jared,

        I appreciate your response. However, as I mentioned in my post, I know how to write the trigger, but am wondering if there is an alternative. This process seems very labor intensive for the person who must write a script for every table, as well as incurring a fair amount of overhead.

Thanks,
Ben

In article <33adee99.100382108_at_news.teleport.com>, jkstill_at_teleport.com (jared still) wrote:
>
>Here is a very basic trigger.
>
>assuming table EMP is:
>
>PK number(12,0);
>LAST_NAME varchar2(20);
>FIRST_NAME varchar2(20);
>
>and emp_sequence is our sequence generator
>
>create or replace trigger emp_pk_trg
>before insert of em
>for each row
>
> pk_seq emp.pk%type;
>
> begin
>
> select emp_sequence.nextval into pk_seq from dual;
> :new.pk := pk_seq;
> end;
>
>/
>
>On Sat, 21 Jun 1997 00:25:09 GMT, asdg_at_sdf.lkj (s) wrote:
>
>>Hi,
>> I realize that this question must have been asked many times.
>>However, I have looked at all the FAQ pages I can find and have looked through
 

>>many manuals for many hours with no luck, so I turn to you.
>> I want to use a sequence to create the next number for a primary key
>>field. All the manuals indicate that this is 'easy' or 'convenient', but none
 

>>of them tell me how.
>> I know that I cannot make reference to the sequence's NEXTVAL in the
>>DEFAULT column in the CREATE TABLE command (though this amazes me).
>> I know how to write a trigger that will fire on an INSERT statement
>>and populate the keyed field with the NEXTVAL. I know that I can also include
 

>>the NEXTVAL in every insert command I ever perform against a table.
>>
>> I just can't believe that I have to do this for every table that I
>>want to have an autoincrementing primary key! There's got to be a better way,
 

>>this just seems incredibly laborious.
>>
>> Any help would be greatly appreciated. Please reply to my email
>>address below (after modification).
>>
>>Thank you,
>>
>>
>>
>>
>>________________________________________________
>>Ben Harmon
>>ben_at_dascom.com.nospam
>>**Please remove .nospam suffix if you want to mail me**
>>________________________________________________
>



Ben Harmon
ben_at_dascom.com.nospam
**Please remove .nospam suffix if you want to mail me**
Received on Tue Jun 24 1997 - 00:00:00 CDT

Original text of this message

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