如何在 Sql Server 2005 上获取上次修改日期时间? [英] How to get last modification datetime on Sql Server 2005?

查看:29
本文介绍了如何在 Sql Server 2005 上获取上次修改日期时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 Sql Server 2005 上获取表的最后修改日期时间?最好不要创建触发器..

Is there any way to get a table's last modification datetime on Sql Server 2005? Preferably without creating triggers..

数据库呢?

EDIT 这个问题的解决方案只考虑了 CREATE 和 ALTER 修改.对于插入、更新和删除,请查看 我的下一个问题

EDIT The solution of this question contemplated only CREATE and ALTER modifications. For INSERT, UPDATE and DELETE please look my next question

推荐答案

这将列出从最近更改到最旧的所有对象类型,您可以根据需要轻松修改...

this will list all object types from most recent change to oldest, you can easily modify as necessary...

DECLARE @SearchParams   varchar(500)
SET @SearchParams='yourObjectName'

SELECT
    CONVERT(varchar(23),modify_date,121) AS modify_date
        ,type_desc
        ,name
    FROM sys.objects
    WHERE is_ms_shipped=0 AND name LIKE '%'+@SearchParams+'%'
    ORDER BY modify_date DESC

如果您只想要桌子,请尝试:

if you just want tables, try:

DECLARE @SearchParams   varchar(500)
SET @SearchParams='YourTableName'
SELECT
    CONVERT(varchar(23),modify_date,121) AS modify_date
        ,type_desc
        ,name
    FROM sys.objects
    WHERE type='U'
        AND name LIKE '%'+@SearchParams+'%' --can use "=@SearchParams" if you have the entire table name
    ORDER BY modify_date DESC

这篇关于如何在 Sql Server 2005 上获取上次修改日期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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