Computed Column with Current DateTime?(当前日期时间的计算列?)
问题描述
我正在尝试创建一个 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.
这篇关于当前日期时间的计算列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:当前日期时间的计算列?
基础教程推荐
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
