问题描述
我正在尝试创建一个 SQL Server 2008R2 表列,并为我插入的每一行自动计算当前日期时间.
I am trying to create a SQL Server 2008R2 Table column with automatically calculated current datetime for every row I insert.
我将此列的计算列规范值设置为 GetDate().我的表中有一些旧数据.添加 GetDate() 函数后,该列将更新为当前日期时间.但我的问题是,当我在此表中插入新行时,我的 datetime 列永远不会更新为当前日期时间,并且此列对于每一行都有相同的值.
I set Computed Column Specification value for this column equals to GetDate(). My table had some old data in it. After adding GetDate() function, the column get updated with current datetime. But my problem is, When i insert new row in this table, my datetime column never get updated with current date time and this column have same value for each row.
当我插入新记录时,我应该使用哪个函数来插入列的当前日期时间值?
Which function should I use to insert current datetime value for column when I insert a new record?
推荐答案
尝试将 GETDATE()
设置为列的 DEFAULT
值.
Try setting GETDATE()
to be the DEFAULT
value for the column.
这篇关于当前日期时间的计算列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!