Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Get the primary key of the last record added
>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 - 8542Received on Wed May 07 1997 - 00:00:00 CDT
![]() |
![]() |