Computed Column with Current DateTime?

痴心易碎 提交于 2019-12-01 20:41:00

问题


I am trying to create a SQL Server 2008R2 Table column with automatically calculated current datetime for every row I insert.

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?

Thanks,


回答1:


Try setting GETDATE() to be the DEFAULT value for the column.




回答2:


You can set the column's default value with the GETDATE(), with this you will get the current DateTime on every new row insert.



来源:https://stackoverflow.com/questions/13171335/computed-column-with-current-datetime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!