Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Computed Column with Current DateTime?

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?

like image 861
jNet Avatar asked Dec 16 '22 17:12

jNet


2 Answers

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

like image 193
SchmitzIT Avatar answered Mar 06 '23 20:03

SchmitzIT


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

like image 44
Pushpendra Avatar answered Mar 06 '23 21:03

Pushpendra