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: auto increment of primary key in ORACLE

Re: auto increment of primary key in ORACLE

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Mon, 09 Aug 1999 12:27:01 GMT
Message-ID: <37b2c8ec.1731579@newshost.us.oracle.com>


A copy of this was sent to wolfgang karrer <wolfgang.karrer_at_ce.uni-linz.ac.at> (if that email address didn't require changing) On Mon, 09 Aug 1999 08:29:46 +0200, you wrote:

>Hi,
>
>is it possible to auto increment the primary key of a table, like
>
>table emp
>empnr INTEGER primary key
>
>thanx for helping me!

sequences are for this.

create sequence emp_seq;

create or replace trigger emp_trigger
before insert on emp for each row
begin

   select emp_seq.nextval into :new.empnr from dual; end;

will do it.

--
See http://govt.us.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'... Current article is "Part I of V, Autonomous Transactions" updated June 21'st  

Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Mon Aug 09 1999 - 07:27:01 CDT

Original text of this message

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