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.
这篇关于当前日期时间的计算列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:当前日期时间的计算列?


基础教程推荐
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01