[英]how to get list of tables which were inserted into or updated in last one hour in sql server
We have a java application that updates / inserts values into the database. 我们有一个Java应用程序,可以将值更新/插入数据库中。
we need to identify the tables it touches during an operation. 我们需要确定操作过程中涉及的表。
is there a way to find the list of tables the code updated/ inserted in the last one hour by a query ? 有没有办法找到通过查询在最近一小时内更新/插入的代码的表列表?
the database is sql server. 该数据库是sql server。
To get list of record for the past hour(x) from specific table 从特定表中获取过去一小时的记录列表
select * from table_name where Col_name> DATEADD(HOUR, -1, GETDATE())
to return list of tables modify past few hours 返回过去几个小时修改的表列表
SELECT OBJECT_NAME(OBJECT_ID) AS DatabaseName, last_user_update,*
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID( 'dbName') and last_user_update> DATEADD(HOUR, -4, GETDATE())
I would simply do a compareTo(). 我只是做一个compareTo()。 But you'll have to do a timestamp for the database.
但是您必须为数据库做一个时间戳记。
LocalTime thisSec;
for (;;) {
thisSec = LocalTime.now();
// implementation of display code is left to the reader
display(thisSec.getHour(), thisSec.getMinute(), thisSec.getSecond());
if (thisSec >= myDB.row(id).timestamp+1)
System.out.println(myDb.row(id));
}
Something like that anyway If you have a myDb.timestamp.row, that considers hrs,mins,secs, and you make .timestamp
that time, this should work. 无论如何,如果您有一个myDb.timestamp.row,它考虑了hrs,mins,secs,并且您将
.timestamp
为该时间,则应该可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.