Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query to find tables modified in the last hour

Tags:

database

mysql

I want to find out which tables have been modified in the last hour in a MySQL database. How can I do this?

like image 635
agente_secreto Avatar asked Mar 22 '10 12:03

agente_secreto


People also ask

How do I get the last modified table in SQL query?

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).

How do I find the last modified column in SQL Server?

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().


1 Answers

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'; 
like image 62
rjh Avatar answered Sep 23 '22 04:09

rjh