简体   繁体   中英

Need To find when table was altered

我在oracle数据库的表中找到了以前不存在的新列,是否有任何方法可以查找表何时被更改。

You can look at the last_ddl_time in user_objects , or all_objects or dba_objects if you aren't connected as the owner:

select last_ddl_time
from user_objects
where object_type = 'TABLE'
and object_name = '<your table name>'

or

select last_ddl_time
from dba_objects
where object_type = 'TABLE'
and owner = '<your table owner>'
and object_name = '<your table name>'

That will tell you the last time any DDL was performed against the table; though that may not be the column addition if any other changes were made later (eg constraints, column modifications, etc.). Remember that the owner and table name need to be in the same case they are stored in the dictionary - usually uppercase (unless you're used quoted identifiers).

Quick demo:

create table t42 (id number);

Table T42 created.

select to_char(last_ddl_time, 'YYYY-MM-DD hh24:MI:SS') as last_change
from user_objects
where object_type = 'TABLE'
and object_name = 'T42';

LAST_CHANGE        
-------------------
2017-05-10 11:12:18

Then some time later...

alter table t42 add (new_column varchar(10));

Table T42 altered.

select to_char(last_ddl_time, 'YYYY-MM-DD hh24:MI:SS') as last_change
from user_objects
where object_type = 'TABLE'
and object_name = 'T42';

LAST_CHANGE        
-------------------
2017-05-10 11:14:22

Sounds like you're after this:

SELECT last_ddl_time
FROM   all_objects
WHERE  object_name = 'YOUR_TABLENAME'
AND    object_type = 'TABLE';

In oracle 11G & 12C we can enable DLL logging

alter system set enable_ddl_logging=true;

The DDL log file data is written in XML format to the file located at ... \\log\\ddl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM