检测 Microsoft Access 数据库表的上次更改时间
有谁知道一种方法来检测 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
检测表中的数据是否已更改的唯一方法是对表执行查询。
您必须向表中添加一个
DATETIME
类型的列,例如名为LastUpdatedDate
的列,该列指示每行的上次更新日期/时间。 将其设为NOT NULL
,以便您必须为每个INSERT
或UPDATE
向该列写入更新的DATETIME
值>。 另外,将该列设置为当前日期戳的默认值DATE()
或当前日期/时间戳的默认值NOW()
。 然后添加验证规则或CHECK
约束,例如CHECK (LastUpdatedDate = NOW())
以确保该列在每次UPDATE
和 <代码>插入。最后,运行
MAX(LastUpdatedDate)
查询,您将获得所需的结果。The only way to detect if data in the table has changed is to perform a query against the table.
You must add a column of type
DATETIME
to the table e.g. namedLastUpdatedDate
that indicates the last updated date/time of each row. Make itNOT NULL
so that you will have to write an updatedDATETIME
value to that column for eachINSERT
orUPDATE
. Also, set the column to have a default ofDATE()
for the current date stamp orNOW()
for the current date/time stamp. Then add a Validation Rule orCHECK
constraint e.g.CHECK (LastUpdatedDate = NOW())
to ensure the column is actually updated on eachUPDATE
andINSERT
.Finally, run a
MAX(LastUpdatedDate)
query and you will get what you need.每次访问表时,没有办法不“手动”写入列。
There isn't a way without "manually" writing to a column each time you access the table.
正如其他人所指出的,如果不自己编码,就无法跟踪更改。
有一个简单的例子
ACC2000:如何在表单中创建记录更改的审计跟踪
http://support.microsoft.com/default.aspx? scid=kb;en-us;Q197592
审核跟踪 - 在记录级别记录更改:
http://allenbrowne.com/AppAudit.html
本文讨论了表单和子表单的编辑、插入和删除。
模块:维护变更历史记录
http://www.mvps.org/access/modules/mdl0021.htm
历史表例程旨在写入历史记录,跟踪对一个或多个表中的字段所做的更改。
As others have indicated there is no way to track changes without coding it yourself.
There's a simple example at
ACC2000: How to Create an Audit Trail of Record Changes in a Form
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q197592
Audit Trail - Log changes at the record level at:
http://allenbrowne.com/AppAudit.html
The article addresses edits, inserts, and deletes for a form and subform.
Modules: Maintain a history of changes
http://www.mvps.org/access/modules/mdl0021.htm
The History Table routine is designed to write history records that track the changes made to fields in one or more tables.
您将需要在表中实现时间戳列,并在数据更改期间更新该值。
You will need to implement a timestamp column in your table, and update the value during your data changes.