Wednesday, 19 June 2019

How to check last modified table in Oracle 10g and Above

As a DBA, application team sometimes might ask you to provide details of last modified table in oracle. The table modification can be insert, update or delete. Below queries get details of last or latest modified table in oracle database. Run the queries depending upon the database version.
 
SQL> conn
Enter user-name: scott
Enter password:
Connected.

SQL> create table emp_new as select * from emp where 1=1;

Table created.

SQL> insert into emp_new values (2790,'alam','SMITH',7698,sysdate,5600,340,30);

1 row created.

SQL> commit;

Commit complete.


SQL> conn
Enter user-name: / as sysdba
Connected.


SQL>exec DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;
 

PL/SQL procedure successfully completed.

SQL>


set linesize 500;
select TABLE_OWNER, TABLE_NAME, INSERTS, UPDATES, DELETES,TRUNCATED,
to_char(TIMESTAMP,'YYYY-MON-DD HH24:MI:SS')
from all_tab_modifications
where table_owner='SCOTT' and
EXTRACT(YEAR FROM TO_DATE(TIMESTAMP, 'DD-MON-RR')) > 2010
order by 6;SQL> SQL> SQL> SQL>   2    3    4    5    6

TABLE_OWNER                    TABLE_NAME                        INSERTS    UPDATES    DELETES TRU TO_CHAR(TIMESTAMP,'Y
------------------------------ ------------------------------ ---------- ---------- ---------- --- --------------------
SCOTT                          EMP_NEW                                 1          0          0 NO  2019-JUN-20 11:55:02

SQL>

No comments:

Post a Comment

Rename Oracle database using NID

  SQL> set pages 999 lines 999; col instance_name for a10; col host_name for a20; col startup_time for a30; set colsep | set underline = ...