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

Home -> Community -> Usenet -> c.d.o.server -> Re: Get the primary key of the last record added

Re: Get the primary key of the last record added

From: Bill Biesty <bill_at_popmail.med.nyu.edu>
Date: 1997/05/07
Message-ID: <3370B84E.1F0C@popmail.med.nyu.edu>#1/1

>Allen Kirby <akirby_at_att.com> wrote:
>You must use a column that
>increases in value with each insertion, then select max of that column.
>Sequence numbers or sysdate usually work fine. This can be implemented
>with triggers, default values or in the application itself.

Hmm. This is not always possible, especially if your sequence numbers are generated to distribute your rows in a cluster instead of piling them at the end. Plus if you commit there's no guarantee that the max will be the record your process inserted, since another process might have also just inserted after yours.

You need to select on an alternate key (set of columns that uniquely identifies the row) in your where clause to get the PK.

How does a trigger or default value return the value of the PK to the application???

Bill

-- 
Bill Biesty, Systems Programmer
Educational Computing - Coles 202
New York University School of Medicine
550 1st Avenue, New York, NY 10016
(212) 263 - 5744 bill_at_popmail.med.nyu.edu
 FAX  263 - 8542
Received on Wed May 07 1997 - 00:00:00 CDT

Original text of this message

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