In MS SQL Server, what's the best way to update an Updated By, Updated On set of fields on a table? I've seen it done it triggers, in the code. etc. The upside I've seen to triggers is that it all happens in the same place. On the downside there are occasions when an administrator has to bulk fix a table and doesn't want to obliterate the username/time of the last user update.
Note: I don't want a timestamp. I want the windows user ID and a human readable date/time of the last change.
Looking for what you recommend and WHY it's a good choice.
Best Answer
1) Your trigger idea is good: we use it sometimes.
It is foolproof mostly except:
You can mitigate this with SET CONTEXT_INFO to control admin behaviour, or more carefully to pass in some end user details.
2) All writes via stored procedures. We use this method mostly.
We also use defaults on UpdatedOn so...
3) Let your client do it. I won't take this any further...
Finally, we implemented "AffectedBy", and "AffectedOn" fields to track admin/indirect updates.