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.
这篇关于当前日期时间的计算列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:当前日期时间的计算列?
基础教程推荐
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 无法解决整理冲突 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
