jNet
jNet

Reputation: 143

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?

Upvotes: 5

Views: 17533

Answers (2)

Pushpendra
Pushpendra

Reputation: 174

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

Upvotes: 1

SchmitzIT
SchmitzIT

Reputation: 9572

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

Upvotes: 14

Related Questions