birwin
asked on
Find the last date a mysql table was written to
Is there a way to find the last date a mysql table was written to? The last written activity would have been an upload of data using a LOAD DATA INTO statement.
ASKER
This is a table that does not have a date field. I was hoping that mysql may have some native way to access the last write date, perhaps from a system log or some internal monitoring module.
I would of thought this would be part of your table design. Does this load data import new records only? Do you have some sort of primary key that is a autoincrement number? if so then you could find that highest number (select max(id) from table)
otherwise good idea to change table to have a last created/last updated date as well.
otherwise good idea to change table to have a last created/last updated date as well.
If you have the ability to modify the db to append a dateCreated datefield, that would make your job much easier.
Otherwise, like @rockiroads suggested, if you have a pk that autoincrements, then use that by either grabbing the latest id (select max(id)...)
or order by id desc - samething, though first option is more reliable.
Otherwise, like @rockiroads suggested, if you have a pk that autoincrements, then use that by either grabbing the latest id (select max(id)...)
or order by id desc - samething, though first option is more reliable.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Learn about the CURRENT_TIMESTAMP data type. Add this as the first such column in your table definition, and MySQL will keep track of this information for you, without any further programming on your part.
Check out DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP here:
http://dev.mysql.com/doc/refman/5.0/en/timestamp.html
HTH, ~Ray
Check out DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP here:
http://dev.mysql.com/doc/refman/5.0/en/timestamp.html
HTH, ~Ray
ASKER
This is a set of legacy tables, not a table that I am designing. There was some confusion over the date of last use of some of the tables, so I was hoping their may be a system log or some method of determining the last write time. If I was designing the tables myself, I would definately use a timestamp or system created date field, but these tables were designed long ago by others.
I really dont know how you are going to achieve this. is it not possible to add a auto incrementing key in this legacy table?
ASKER
It would be, but that doesn't answer my current problem, which is determining the time of last write for the existing, archived tables.
It appears that this is not possible.
It appears that this is not possible.
If the question is more like, "What can I point to for a past event?" you may not be able to find an answer. MySQL is well equipped to help you keep track of updates, but if the tables were designed in such a way that these features of MySQL were deliberately omitted, your audit trail simply does not exist.
Going forward, you can easily use ALTER TABLE to add the CURRENT TIMESTAMP column. It adds nearly zero overhead. Transaction logging is not a bad idea, either.
Best regards, ~Ray
Going forward, you can easily use ALTER TABLE to add the CURRENT TIMESTAMP column. It adds nearly zero overhead. Transaction logging is not a bad idea, either.
Best regards, ~Ray
>> It appears that this is not possible.
AFAIK - that is the case.
AFAIK - that is the case.
ASKER
When I first tried this , I got an error. But I had misread the dot between informationa_schema and TABLES. When I tried it again, with a period between them, it worked. Thank you.
sorry, question not too clear?