I want to find out which tables have been modified in the last hour in a MySQL database. How can I do this?
SELECT name AS TableName, create_date AS CreatedDate, modify_date as ModifyDate FROM sys. tables order by ModifyDate; ...will tell me the last time a table was created and modified (from a DDL perspective).
Solution. Using a SQL Server trigger to check if a column is updated, there are two ways this can be done; one is to use the function update(<col name>) and the other is to use columns_updated().
MySQL 5.x can do this via the INFORMATION_SCHEMA database. This database contains information about tables, views, columns, etc.
SELECT * FROM `INFORMATION_SCHEMA`.`TABLES` WHERE DATE_SUB(NOW(), INTERVAL 1 HOUR) < `UPDATE_TIME`
Returns all tables that have been updated (UPDATE_TIME) in the last hour. You can also filter by database name (TABLE_SCHEMA column).
An example query:
SELECT CONCAT(`TABLE_SCHEMA`, '.', `TABLE_NAME`) AS `Table`, UPDATE_TIME AS `Updated` FROM `INFORMATION_SCHEMA`.`TABLES` WHERE DATE_SUB(NOW(), INTERVAL 3 DAY) < `UPDATE_TIME` AND `TABLE_SCHEMA` != 'INFORMATION_SCHEMA' AND `TABLE_TYPE` = 'BASE TABLE';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With