Re: SQL Server Autonumber equivalent in Oracle 8i

From: <mikkrolewski_at_my-deja.com>
Date: Mon, 20 Nov 2000 18:29:44 GMT
Message-ID: <8vbqic$nmr$1_at_nnrp1.deja.com>


[Quoted] In article <8vbpap$mjr$1_at_nnrp1.deja.com>,   jkipp_at_my-deja.com wrote:
> In article <8vbgkh02kif_at_enews3.newsguy.com>,
> "Robert Martin" <rwmartin_at_sisconet.com> wrote:
> > I am a newbie to Oracle and I have read that I can create an SQL
 Server
> > Autonumber equivalent by using a sequence and a trigger. My problem
 is, I
> > have never written a trigger. I created my sequence, and from the
 looks of
> > it in the OEM it appears to be fine. How do I write the trigger?
 Does
 anyone
> > know of any good documentation on the net on writing Oracle
 triggers?
 Please
> > help. Thanks :)
> >
> > Oh and I am working in NT
>
> My question is very similar to yours. See: creating sequence for
> autonumber. I am too wondering about triggers. I will let you know
 what
> I can find out.
>
> JIm
>
> > -------------------------------------------
> > Robert Martin (rwmartin_at_sisconet.com)
> > Design Engineer
> > SISCO Inc,
> > 6605 19 1/2 Mile Road
> > Sterling Heights, MI 48314-1408
> > Phone : 810-254-0020 (ext 125)
> > Fax : 810-254-0053
> >
> >
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

[Quoted] [Quoted] Most of these questions are part of the user manuals supplied by Oracle.

[Quoted] [Quoted] You might try investing in some of the Oracle books like the Oracle 8i The Complete Reference by Osborne press for about $70.

create or replace trigger autoincrement
[Quoted] before insert on <table>
for each row
begin

[Quoted] [Quoted] :new.<field> := <seq>.nextval;
end;

[Quoted] [Quoted] where <table> is the name of the table, <seq> is the name of the sequence, etc.

[Quoted] I am reasonably sure this will work -- did not try it on database.

[Quoted] [Quoted] Obviously, this will consume sequences if you roll back an insert as the trigger is used every time an row insert is attempted.

Michael Krolewski

Sent via Deja.com http://www.deja.com/
Before you buy. Received on Mon Nov 20 2000 - 19:29:44 CET

Original text of this message