Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out when a particular table was created in Oracle?

In Oracle, is there a way to find out when a particular table was created?

Similarly, is there a way to find out when a particular row was inserted/last updated?

like image 988
Moeb Avatar asked Dec 14 '10 17:12

Moeb


People also ask

How do I find out when a table was created?

To see the table created date and time from properties window: In the Object Explorer in SQL Server Management Studio, go to the database and expand it. Under the Tables folder select the table name. Right click and select Properties from the menu.

How can you tell when a table was created by a user?

At the most basic level, you may wish to view a list of all the tables owned by the current Oracle user. This can be accomplished with a simple SELECT query on the USER_TABLES data dictionary. This will return a list of all tables that the current user is owner of, as specified in the owner column.

How can I tell when a table was last DDL?

The last DDL time is easy: select last_ddl_time from user_objects where object_name = :tab; As you're finding, if you've not got auditing, last DML write time is a little trickier...


2 Answers

SELECT created   FROM dba_objects  WHERE object_name = <<your table name>>    AND owner = <<owner of the table>>    AND object_type = 'TABLE' 

will tell you when a table was created (if you don't have access to DBA_OBJECTS, you could use ALL_OBJECTS instead assuming you have SELECT privileges on the table).

The general answer to getting timestamps from a row, though, is that you can only get that data if you have added columns to track that information (assuming, of course, that your application populates the columns as well). There are various special cases, however. If the DML happened relatively recently (most likely in the last couple hours), you should be able to get the timestamps from a flashback query. If the DML happened in the last few days (or however long you keep your archived logs), you could use LogMiner to extract the timestamps but that is going to be a very expensive operation particularly if you're getting timestamps for many rows. If you build the table with ROWDEPENDENCIES enabled (not the default), you can use

SELECT scn_to_timestamp( ora_rowscn ) last_modified_date,        ora_rowscn last_modified_scn,        <<other columns>>   FROM <<your table>> 

to get the last modification date and SCN (system change number) for the row. By default, though, without ROWDEPENDENCIES, the SCN is only at the block level. The SCN_TO_TIMESTAMP function also isn't going to be able to map SCN's to timestamps forever.

like image 145
Justin Cave Avatar answered Oct 06 '22 01:10

Justin Cave


You can query the data dictionary/catalog views to find out when an object was created as well as the time of last DDL involving the object (example: alter table)

select *    from all_objects   where owner = '<name of schema owner>'    and object_name = '<name of table>' 

The column "CREATED" tells you when the object was created. The column "LAST_DDL_TIME" tells you when the last DDL was performed against the object.

As for when a particular row was inserted/updated, you can use audit columns like an "insert_timestamp" column or use a trigger and populate an audit table

like image 38
bhangm Avatar answered Oct 06 '22 00:10

bhangm