在Microsoft Access数据库表上检测上次更改的时间 [英] Detect time of last change on a Microsoft Access database table
问题描述
有人知道一种方法来检测上一次更改(插入或更新)Microsoft Access表的时间吗?我们通过ADO COM使用OLEDB通过编程方式与访问数据库进行通信,并且正在寻找一种检测特定表更改的方法.我们不需要知道这些更改是什么,只需进行更改即可.
Does anyone know of a way to detect when the last time a Microsoft Access table has been changed (inserted into or updated)? We used OLEDB via ADO COM to communicate with an access database programmatically and were looking for a way of detecting changes to specific tables. We don't need to know what those changes are, just that changes were made.
推荐答案
检测表中数据是否已更改的唯一方法是对表执行查询.
The only way to detect if data in the table has changed is to perform a query against the table.
您必须将DATETIME
类型的列添加到表中,例如名为LastUpdatedDate
的名称,指示每行的最后更新日期/时间.将其设置为NOT NULL
,这样您将必须为每个INSERT
或UPDATE
将更新的DATETIME
值写入该列.另外,将列设置为默认值DATE()
作为当前日期戳或NOW()
作为当前日期/时间戳.然后添加验证规则或CHECK
约束,例如CHECK (LastUpdatedDate = NOW())
以确保实际上在每个UPDATE
和INSERT
上都更新了该列.
You must add a column of type DATETIME
to the table e.g. named LastUpdatedDate
that indicates the last updated date/time of each row. Make it NOT NULL
so that you will have to write an updated DATETIME
value to that column for each INSERT
or UPDATE
. Also, set the column to have a default of DATE()
for the current date stamp or NOW()
for the current date/time stamp. Then add a Validation Rule or CHECK
constraint e.g. CHECK (LastUpdatedDate = NOW())
to ensure the column is actually updated on each UPDATE
and INSERT
.
最后,运行MAX(LastUpdatedDate)
查询,您将获得所需的内容.
Finally, run a MAX(LastUpdatedDate)
query and you will get what you need.
这篇关于在Microsoft Access数据库表上检测上次更改的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!