Re: Last row?

From: Michael Krolewski <vandra_at_u.washington.edu>
Date: Tue, 25 Aug 1998 23:36:22 -0700
Message-ID: <35E3ACE5.AB159601_at_u.washington.edu>


There is a minor problem with the request.

SQL by design does not really care which order or position a particular record is inserted into a table. All rows are equal, order is insignificant.

If you want to track the order, generally, one creates some sort of mechanism
to identify the order of insertion.

One is a time stamp via a date field. Explicitly set the field or use a trigger to
assign a value to a date field. Major problem -- Oracle tracks time to the
nearest second. If records are insert more often, they cannot be differentiated.

Another one is to use a sequence number. Again either explicitly or via a trigger
assign the next value of the sequence number as each record is added. Sequence
numbers can be constructed to recycle or not. If you look at the current value
for the sequence number -- you know the last record (assuming no one has deleted it
already).

Testing for the max value of the sequence is better.

Mike Krolewski.

Paloma Angulo wrote:

> Hi
> How can I know wich the last row inserted in a table with INSERT?
> Thank in advance
Received on Wed Aug 26 1998 - 08:36:22 CEST

Original text of this message