Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantages to storing UserId instead of Username in sql audit columns such as CreatedBy/ModifiedBy [closed]

I have always wondered why in most examples/tutorials everyone stores the User's name in audit database columns such as CreatedBy/ModifiedBy.

In the back of my head I have always wondered, what if the system I am building will allow the user to change their username as long as it is not taken.

Wouldn't I want to store the user's Id in this case?

I really don't want this to be an opinion based question. So the kind of answer I expect is a situation when storing the user's name in audit columns is fine and a situation when storing the user's id in audit columns is fine.

like image 403
Blake Rivell Avatar asked Feb 15 '16 16:02

Blake Rivell


People also ask

Which three targets can be configured for auditing?

Target. The results of an audit are sent to a target, which can be a file, the Windows Security event log, or the Windows Application event log.

How do I track user activity in SQL Server?

Object ExplorerRight-click on the top-level object for a SQL Server connection, and select Activity Monitor.

What is login auditing in SQL Server?

Enabling SQL login auditing will help you detect insider and outsider threats in time to protect your SQL databases against data breaches. These capabilities are included in SQL Server audit services, but this is not a very convenient solution because truly suspicious events get buried in the huge amount of noise data.


1 Answers

There is no chance this isn't an opinion based question. However, consider what happens when you use the UserID. The next logical conclusion is to make a foreign key to the user table. Now you can't delete a user if they have an audit row.

Ok no biggie. Skip the foreign key and put in the UserID with no foreign key. Now how useful is the audit information if the User row is deleted? Especially if you have an identity or uniqueidentifier as your UserID. The value is now completely useless because to derive ANY value from it you have to join to your user table.

Now does it make sense why most of the time you see UserName instead of UserID?

like image 145
Sean Lange Avatar answered Sep 23 '22 07:09

Sean Lange