如何获取最近更新的数据 [英] how to get last updated data

查看:77
本文介绍了如何获取最近更新的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,
我有一张桌子,客户的所有数据都可用.我想从所有客户的此表中检索最近更新的状态数据.我需要所有客户的状态.

Dear,
i have a one table where all data of customer availeble. i want to retrive last updated status data from this table of all customer.i needs all customers status

推荐答案

除非您为状态加盖章,否则没有可靠的方法去做.除非已指定,否则SQL不必以任何特定顺序返回记录.

如果您这样做,那就很简单:
Unless you date stamp your status, there is no reliable way to do that. SQL does not have to return records in any particular order unless it is specified.

If you do then it is simple:
SELECT TOP 1 * FROM myTable ORDER BY lastUpdatedDate DESC


这是查看表的最后更新日期的最佳方法之一:

SELECT OBJECT_NAME(OBJECT_ID)AS数据库名称,last_user_update,*
从sys.dm_db_index_usage_stats
WHERE database_id = DB_ID(``数据库名称'')
AND OBJECT_ID = OBJECT_ID(``tablename'')
this is one of the best way to see the last update date for a table:

SELECT OBJECT_NAME(OBJECT_ID) AS DatabaseName, last_user_update,*
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID( ''Databasename'')
AND OBJECT_ID=OBJECT_ID(''tablename'')


在您的表中添加一个陈述为createdate的文件,并将默认值设置为getdate()函数
现在可以检索像
这样的您的recors
从表顺序中选择*由createdate desc
add one filed say createdate in your table and set the default values as getdate() function
now retrieve ur recors like

select * from table order by createdate desc


这篇关于如何获取最近更新的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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