查找上次更新的时间表 [英] Find the last time table was updated

查看:39
本文介绍了查找上次更新的时间表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索上次更新表的时间(插入、删除、更新).

I want to retrieve the last time table was updated(insert,delete,update).

我试过这个查询.

SELECT last_user_update
FROM sys.dm_db_index_usage_stats
WHERE object_id=object_id('T')

但是那里的数据不会在服务重启后保持不变.

but the data there is not persisted across service restarts.

即使服务重新启动,我也想保留统计信息.我怎样才能实现它?

I want to preserve the stats even if the service restarts. How can I achieve it?

推荐答案

如果您在谈论上次更新表时,它的结构发生了变化(添加了新列、更改了列等) - 使用此查询:

If you're talking about last time the table was updated in terms of its structured has changed (new column added, column changed etc.) - use this query:

SELECT name, [modify_date] FROM sys.tables

如果您在谈论 DML 操作(插入、更新、删除),那么您要么需要定期保留该 DMV 提供给您的内容,要么您需要在所有表上创建触发器以记录上次修改" 日期 - 或查看更改数据捕获等功能SQL Server 2008 及更新版本.

If you're talking about DML operations (insert, update, delete), then you either need to persist what that DMV gives you on a regular basis, or you need to create triggers on all tables to record that "last modified" date - or check out features like Change Data Capture in SQL Server 2008 and newer.

这篇关于查找上次更新的时间表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆