Connecting Tech Pros Worldwide Help | Site Map

How to get the date of the last update of the database?

Newbie
 
Join Date: May 2007
Posts: 1
#1: May 4 '07
Hello.

Do you know if there is a function or query that shows me the date/time of the last update, insert or delete of a record in a certain database?

Thanks in advance
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: May 6 '07

re: How to get the date of the last update of the database?


By default, no. However, you can set this up by creating a last_updated (or whatever you want to call it) field and use a trigger to automatically touch this every time a row is updated.

Expand|Select|Wrap|Line Numbers
  1. delimiter |
  2. CREATE TRIGGER `setUpdateTimestamp` BEFORE UPDATE ON `tablename` 
  3.  FOR EACH ROW
  4.   BEGIN
  5.    SET NEW.`last_updated` = NOW();
  6.   END;|
  7. delimiter ;
  8.  
Newbie
 
Join Date: Jul 2007
Posts: 1
#3: Jul 23 '07

re: How to get the date of the last update of the database?


Quote:

Originally Posted by asantos

Hello.

Do you know if there is a function or query that shows me the date/time of the last update, insert or delete of a record in a certain database?

Thanks in advance



Hi dear .... I too got stuck with this ... so pls send me reply to <Removed>or hear.... ThanQ in advance dear............
mwasif's Avatar
Moderator
 
Join Date: Jul 2006
Location: Pakistan
Posts: 718
#4: Jul 23 '07

re: How to get the date of the last update of the database?


Quote:

Originally Posted by pbmods

By default, no. However, you can set this up by creating a last_updated (or whatever you want to call it) field and use a trigger to automatically touch this every time a row is updated.

Expand|Select|Wrap|Line Numbers
  1. delimiter |
  2. CREATE TRIGGER `setUpdateTimestamp` BEFORE UPDATE ON `tablename` 
  3.  FOR EACH ROW
  4.   BEGIN
  5.    SET NEW.`last_updated` = NOW();
  6.   END;|
  7. delimiter ;
  8.  

What about creating a timestamp field?
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#5: Jul 23 '07

re: How to get the date of the last update of the database?


Quote:

Originally Posted by mwasif

What about creating a timestamp field?

LOL or instead of any of my complicated ideas, you can use a timestamp field whose default can be set to... CURRENT_TIMESTAMP :P

Only the timestamp type does this, though, which is curious.
Reply