If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How to get the last timestamp a table was altered

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-10-07, 23:32
sundaram sundaram is offline
Registered User
 
Join Date: Mar 2006
Posts: 104
How to get the last timestamp a table was altered

Hi

Db2 8.2.6 on windows

Would like to know how to get the last timestamp a table was altered. I can get get the create_time of table from syscat.tables, but I cannot see anything there as to when a table was altered.


Thanks

Hari Kumar

Last edited by sundaram; 05-10-07 at 23:34. Reason: Corerct typo in subject
Reply With Quote
  #2 (permalink)  
Old 05-11-07, 04:39
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,279
You could write a stored procedure (sp) to keep that bookkeeping information for you.

Each time a record is inserted, updated or deleted from that table another table could be updated to reflect that event.

Or, something that is very often done, write a sp that stores per record when it was created, who did it and when it was last updated and by who and a counter that stores the number of updates.

If you only need to know the information for a whole table, the fastest way to accomplish this is the first solution, though with high insert/update/delete loads, the table that stores the bookkeeping info could become a bottleneck.
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 16
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages
Reply With Quote
  #3 (permalink)  
Old 05-11-07, 08:27
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Wim's solution would work, but only if you are able to force everyone to use the Stored Procedure to do all of the insert/update/deletes. If you cannot guarantee that every user will use the Stored Procedures, you should create triggers to log the information. That way no one will be able to bypass the logging. DB2 by itself does not track this info.

Andy
Reply With Quote
  #4 (permalink)  
Old 05-11-07, 16:41
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
I believe that the OP wants to know when the schema (number of columns, types of the columns, constraints, ...) of the table were changed - not the content of the table. As far as I know, there is nothing in the DB2 catalog to provide that information.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #5 (permalink)  
Old 05-13-07, 06:01
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,279
My error, i meant to use triggers (instead of stored procedures) to do all that bookeeping.

Quote:
Originally Posted by ARWinner
Wim's solution would work, but only if you are able to force everyone to use the Stored Procedure to do all of the insert/update/deletes. If you cannot guarantee that every user will use the Stored Procedures, you should create triggers to log the information. That way no one will be able to bypass the logging. DB2 by itself does not track this info.
Andy
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 16
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages
Reply With Quote
  #6 (permalink)  
Old 05-13-07, 06:03
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,279
There is still something like a log to keep all the modifications one has applied to a databse.
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 16
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages
Reply With Quote
  #7 (permalink)  
Old 05-13-07, 09:53
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Quote:
Originally Posted by Wim
There is still something like a log to keep all the modifications one has applied to a databse.
Right. But with that argument, you wouldn't need triggers or whatever to track data changes either.

The log is not such a good alternative because it is (mostly) for DB2-internal purposes only to ensure the durability and consistency of a database.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #8 (permalink)  
Old 05-13-07, 20:50
sundaram sundaram is offline
Registered User
 
Join Date: Mar 2006
Posts: 104
Thanks for the reply Stolze.

I take it from your statement that there are no catlog info in DB2 as to when exactly a table structure was modified.

hari
Reply With Quote
  #9 (permalink)  
Old 05-14-07, 08:05
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Quote:
Originally Posted by sundaram
I take it from your statement that there are no catlog info in DB2 as to when exactly a table structure was modified.
Not that I'm aware of, no.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #10 (permalink)  
Old 05-16-07, 00:25
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
ya there is nothing in catalog tables
but if you activate db2audit then u can keep track of the ddl changes
and all other changes made by various authorities
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On