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


- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- SQL 临时表问题 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01