Find the time when table was last accessed in Db2 database

Article for: SQL Server Teradata Vertica

Query below returns list of tables and their last using date.

Query

select tabschema || '.' || tabname as table,
       lastused as last_used,
       create_time,
       alter_time
from syscat.tables
where tabschema not like 'SYS%'
      and type = 'T'
order by lastused desc;

Columns

  • table - name of the table schema
  • last_used - date of last table use in DDL query
  • create_time - time at which the table was created.
  • alter_time - time at which the table was last altered.

Rows

  • One row represents one table in database
  • Scope of rows: all tables in database
  • Ordered by last used date

Sample results

sample results