Boric
Boric

Reputation: 872

Best way to keep track of when a table was last updated?

I have a program that retrieves data and stores it in a table each day, and then another program that queries that data to produce reports. The reports need to say when the data was last updated, so we know how old the information is.

It seems wasteful to add a column with the last update date to the table, since all the rows will have the same value. It also seems wasteful to create a table just to store one value.

What is the best solution for keeping track of the last time a table was updated?

Upvotes: 0

Views: 2672

Answers (3)

Hieu Nguyen
Hieu Nguyen

Reputation: 404

My preferred way is to create a new "report" table to store the last time the target table is updated, and create a trigger to update the "report" table whenever there is change on the target table.

See this for more information on creating such trigger: http://www.techonthenet.com/oracle/triggers/after_update.php

Upvotes: 1

Seth T
Seth T

Reputation: 305

This should help: http://docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_2097.htm

ALL_TAB_MODIFICATIONS describes tables accessible to the current user that have been modified since the last time statistics were gathered on the tables. TIMESTAMP DATE Indicates the last time the table was modified

So:

select TIMESTAMP from ALL_TAB_MODIFICATIONS
where table_name = 'My_TABLE'

Upvotes: 0

Ankit Khetan
Ankit Khetan

Reputation: 138

You Probably should add a column "LastModified" and save the datetime when its getting updated. This should be the best way to identify when your table was last updated.

Upvotes: 1

Related Questions