Just wondering if there's a preferred method or Best Practice for storing "Updated By" type fields in a database. I tend to see just the name of the user being stored pretty frequently, but I've been designing my tables with the ID of the user who last updated that table.
Is there a reason to use one method over the other? I like my method for having a nice backreference to get to the user... on the other hand it also generally means you can never delete the user (if you also use this for Created By anyway) so maybe that's enough reason not to? Not to mention how messy diagrams or ORM mappings seem to get when everything has to point back at the one table...
Definitely store an id instead of a name. Otherwise what do you do if someone wants to change their username for some reason?
In most systems users should never be deleted. Just have an "Active" flag, or something equivalent.
If you have a way to tie the update to a user that's represented by an entity in the database, then use that. If you don't have that sort of mechanism in place (no users in the database, for instance), then storing the username is fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With