与Access中的TIMESTAMP数据类型有什么相同? [英] What is same as TIMESTAMP datatype in Access?

查看:127
本文介绍了与Access中的TIMESTAMP数据类型有什么相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于自动日期\时间,我们在SQL中使用TIMESTAMP数据类型.什么相当于MS Access 2007中的数据类型...

For auto date\time we use TIMESTAMP datatype in SQL. What is equivalent to that datatype in MS Access 2007...

推荐答案

Access中没有完全相同的内容.
需要澄清的是,SQL中的TIMESTAMP并不总是可用的日期/时间,例如在不推荐使用SQL Server ,它等效于ROWVERSION,该值始终返回一个唯一值,即使它的值是从当前时间松散派生的,它也不用于跟踪日期和时间.

There is no exact equivalent in Access.
To clarify, TIMESTAMP in SQL is not always a usable Date/Time, for instance in SQL Server it is deprecated and equivalent to ROWVERSION, which always returns a unique value and it not used to track date and time, even though its value is loosely derived from the current time.

但是,假设您要跟踪记录的更改.
在Access中,可以通过以下方式自动将字段设置为DateTime:

But let's say you want to track changes to records.
In Access, the following ways let you set a field to a DateTime automatically:

首先,您可以将=Now分配为表中DateTime字段的默认值.这将在创建记录时分配当前时间(但在更改记录时不会自动更新).

First, you can assign =Now as the default value for a DateTime field in a table. This will assign the current time when the record is created (but will not update it automatically when the record is changed).

要在更改时记录当前的DateTime,必须在VBA中或通过宏对其进行编程:

For recording the current DateTime whenever you make a change, you will have to program that in VBA or through Macros:

  • 遍历记录集时,只要对记录进行更改,只需更新您的!ModifiedDateTime或(无论您叫什么字段).

  • When going through a recordset, just update your !ModifiedDateTime or (whatever you called your field) whenever you make a change to a record.

当表/查询绑定到表单时,可以通过处理表单的BeforeUpdate事件来让表单更新您的ModifiedDateTime字段:

When your table/query is bound to a form, you can let the form update your ModifiedDateTime field by handling the BeforeUpdate event of the form:

Private Sub Form_BeforeUpdate(Cancel As Integer)
    ModifiedDateTime = Now
End Sub

如果您使用查询而不是表格来绑定到表单,请确保查询中存在该字段.

If you use a query rather than a table to bind to the form, make sure that the field is present in the query.

在Access 2010和更高版本中,您还可以使用新的数据宏(与触发器等效的Access)来记录更改时的当前日期和时间.
这种方法的移植性较差,但可能比使用VBA更为可靠,因为您无需在修改记录时就记得对它进行编码(数据宏在ACE数据库驱动程序级别进行处理).

In Access 2010 and later, you may also use the new Data Macro, which are the Access equivalent of triggers, to record the current date and time when a record changes.
This is less portable, but would probably be more reliable than using VBA since you don't have to remember to code it whenever you modify a record (Data Macros are handled at the ACE database driver level).

There are tons of articles on how to create audit trails in Access if that is what you are looking for.

这篇关于与Access中的TIMESTAMP数据类型有什么相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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