Re: Autonumber in Oracle

From: (wrong string) és Lopehandía Marticorena <alopehan_at_auge.cl>
Date: Wed, 22 Sep 1999 18:50:11 GMT
Message-ID: <01bf052b$53e34880$0601000a_at_Andres.auge.cl>


You can get a similar "autonumber" functionality programing an easy to code "before insert trigger" that gets the next value of the sequence and put it into the table for you.

Let supose that we have a table named A with a primary key column named id.  We also have a sequence called A_seq.

The following code builds the trigger who generates the primary key automatically.

create or replace trigger TBI_A before insert on A

begin
  --this generates de
  select A_seq.nextval
  into :new.id
  from dual;
end;

For further information look for triggers into the orcle documentation.

Mike Phillips <mlp_at_swsdot.com> escribió en artículo <%10G3.4066$OT2.136386_at_wbnws01.ne.mediaone.net>...
> Question: Is there autonumber functinality in oracle like in access?
Also,
> is it still a good idea then,
> to create a separate artificial recordID (autonumber) column for each
table
> as the primary key. Or should we actually use real column values, for
eg.:
[Quoted] > the combination of 'PartNumber+VendorID' values as the primary key for
the
> tables, keeping in mind that in the end all records in a relational table
> must be unique. I personally liked the autonumber
> idea in MSAccess.
>
> Mike
>
>
>
>
>
Received on Wed Sep 22 1999 - 20:50:11 CEST

Original text of this message