简体   繁体   English

需要查找表何时更改

[英]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: 你可以看一下在last_ddl_timeuser_objects ,或all_objectsdba_objects如果你没有连接作为所有者:

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; 这将告诉您上一次对表执行任何DDL的时间; 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 在Oracle 11G和12C中,我们可以启用DLL日志记录

alter system set enable_ddl_logging=true;

The DDL log file data is written in XML format to the file located at ... \\log\\ddl DDL日志文件数据以XML格式写入位于... \\log\\ddl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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