Ask the Expert

Last updated row

Is there any way to find the last updated row in a specific table?

    Requires Free Membership to View

The answer depends on the database version, which you did not specify. If you are using Oracle 8i or 9i, you can use LogMiner to mine your archived redo logs to determine which row was last updated in the table. In Oracle 10g, you can use a Flashback Versions Query to see the updates to the table.

The above methods can be used after the fact. Before the fact, you can add a column to the table called UPDATE_TIME defined with the DATE datatype. Then create a trigger on the table which sets the UPDATE_TIME column to SYSDATE on any INSERT or UPDATE command on the table. Determining the last updated row is as simple as querying for the row with the MAX(UPDATE_TIME) value. This method does require you to set up the column and trigger beforehand.

This was first published in July 2006

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: