How to implement automatic timestamps for record changes (SQL Server)

I use the "changed_at" fields in my MySQL database, which Ruby on Rails automatically updates when a record changes.

Now I'm using ASP.NET MVC with SQL Server 2008, and I'm wondering how I will get the same functionality. Does SQL Server have the ability to automatically update a field when updating?

+6
timestamp sql-server asp.net-mvc
source share
4 answers

The "timestamp" data type gives you a binary value that is automatically updated every time your field changes, but it will not give you a good date / time value.

+4
source share

You can use a trigger or just update it in sp, which performs the update.

+1
source share

do it...

UPDATE YourTable SET Column1=@... ,@ Column2=@.... ,@ Column3=@... ,changed_at=GETDATE() WHERE ... 
+1
source share

You can also use rowversion , which has the same effect but is supported in the future.

Link - http://msdn.microsoft.com/en-us/library/ms182776.aspx

0
source share

All Articles