Thursday, February 16, 2012

Auto update a field with the current date/time

How can I set a column in a table to auto update the date and time everytime something in that row is updated or when the row is first added?

Thanks ahead for the help,

Jason

Check out BOL to see if the timestamp column can solve your requirements.|||I want to be able to query on this and my understanding of timestamp is that it doesn't actually store dates. Is this incorrect?|||

That is correct. You can set the default value for a column to getdate() or getutcdate(). That takes care of the inserts (if the column isn't mentioned in the insert statement).

For the updates, you'll need to write an update trigger.

|||

jasonburrwc84:

I want to be able to query on this and my understanding of timestamp is that it doesn't actually store dates. Is this incorrect?

Trigger is covered in the thread below. Hope this helps.

http://forums.asp.net/thread/1071147.aspx

No comments:

Post a Comment