Audit columns – Created by and Updated By
I have seen two database designs to store the value in Created by and Updated By columns as:
- Store the PK of user in Created by and Updated By columns
- Store the user name in Created by and Updated By columns
Now you may have question: What is best practice to store the value in the Created by and Updated By columns and why?
My opinion is PK of user (user id) is preferred over user name. There are various reasons, some of them are mentioned below:
- User id is integer and User name is char/varchar. Integer occupies less space and works faster in terms of indexing.
- User id never gets changed, whereas user name can be changed over a period of time.
- With user id, you can retrieve other information for user master, but will be expensive to do it through user name.
- Data validation can be done through FK for user id and not for user name.
You may share your opinion or comment.