Re: SQL Server Autonumber equivalent in Oracle 8i

From: Sybrand Bakker <postbus_at_sybrandb.demon.nl>
Date: Mon, 20 Nov 2000 19:02:37 +0100
Message-ID: <974744311.11943.2.pluto.d4ee154e_at_news.demon.nl>


"Robert Martin" <rwmartin_at_sisconet.com> wrote in message news:8vbgkh02kif_at_enews3.newsguy.com...
> 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
>
> -------------------------------------------
> 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
>
>

What's wrong with reading
a) the Oracle Sql reference manual
b) the Oracle Application Developers Guide

Also *please* do not crosspost to all Oracle newsgroups.

As to your question
create or replace trigger <triggername> before insert on <yourtable> before each row
begin
select <sequence>.nextval
into :new.<keycolumn>
from dual;
end;
/

which you could have easily found consulting the docs.

Regards,

Sybrand Bakker, Oracle DBA Received on Mon Nov 20 2000 - 19:02:37 CET

Original text of this message