【问题标题】:Need To find when table was altered需要查找表何时更改
【发布时间】:2017-05-10 09:47:22
【问题描述】:

我在我的 oracle 数据库 的表中发现了一个以前不存在的新列。有什么方法可以找到表何时更改。

【问题讨论】:

    标签: sql oracle11g database-administration


    【解决方案1】:

    如果您没有以所有者身份连接,您可以查看user_objectsall_objectsdba_objects 中的last_ddl_time

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

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

    这将告诉您上次对表执行任何 DDL 的时间;尽管如果稍后进行了任何其他更改(例如约束、列修改等),这可能不是列添加。请记住,所有者和表名的大小写必须相同,它们存储在字典中 - 通常为大写(除非您使用带引号的标识符)。

    快速演示:

    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
    

    然后过一段时间……

    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
    

    【讨论】:

      【解决方案2】:

      听起来你在追求这个:

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

      【讨论】:

        【解决方案3】:

        在 oracle 11G 和 12C 中,我们可以启用 DLL 日志记录

        alter system set enable_ddl_logging=true;
        

        DDL 日志文件数据以 XML 格式写入位于 ... \log\ddl 的文件中

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-04-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-02-18
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多