记录添加到表中的日期/时间戳? [英] Date / Timestamp to record when a record was added to the table?
本文介绍了记录添加到表中的日期/时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道我可以使用这样的函数在用户向数据库表中添加记录时在列中添加自动日期和时间戳?
Does anyone know of a function as such that I can use to add an automatic date and timestamp in a column for when a user adds a record to the database table?
推荐答案
您可以在表上创建不可为空的 DATETIME 列,并在其上创建 DEFAULT 约束以在添加行时自动填充.
You can create a non-nullable DATETIME column on your table, and create a DEFAULT constraint on it to auto populate when a row is added.
例如
CREATE TABLE Example
(
SomeField INTEGER,
DateCreated DATETIME NOT NULL DEFAULT(GETDATE())
)
这篇关于记录添加到表中的日期/时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文