What's the best way to audit log DELETEs?

ぃ、小莉子 提交于 2019-12-02 08:49:35

问题


The user id on your connection string is not a variable and is different from the user id (can be GUID for example) of your program. How do you audit log deletes if your connection string's user id is static?

The best place to log insert/update/delete is through triggers. But with static connection string, it's hard to log who delete something. What's the alternative?


回答1:


With SQL Server, you could use CONTEXT_INFO to pass info to the trigger.

I use this in code (called by web apps) where I have to use triggers (eg multiple write paths on the table). This is where can't put my logic into the stored procedures.




回答2:


We have a similar situation. Our web application always runs as the same database user, but with different logical users that out application tracks and controls.

We generally pass in the logical user ID as a parameter into each stored procedure. To track the deletes, we generally don't delete the row, just mark the status as deleted, set the LastChgID and LastChgDate fields accordingly. For important tables, where we keep an audit log (a copy of every change state), we use the above method and a trigger copies the row to a audit table, the LastChgID is already set properly and the trigger doesn't need to worry about getting the ID.



来源:https://stackoverflow.com/questions/695817/whats-the-best-way-to-audit-log-deletes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!