审核日志删除的最佳方法是什么?

发布于 2024-07-16 05:28:04 字数 154 浏览 4 评论 0原文

连接字符串上的用户 ID 不是变量,并且与程序的用户 ID(例如可以是 GUID)不同。 如果连接字符串的用户 ID 是静态的,如何审核日志删除?

记录插入/更新/删除的最佳位置是通过触发器。 但是使用静态连接字符串,很难记录谁删除了某些内容。 还有什么选择呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ˇ宁静的妩媚 2024-07-23 05:28:04

对于 SQL Server,您可以使用 CONTEXT_INFO 将信息传递给触发器。

我在代码中使用它(由网络应用程序调用),其中我必须使用触发器(例如表上的多个写入路径)。 这是无法将我的逻辑放入存储过程的地方。

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.

安稳善良 2024-07-23 05:28:04

我们也有类似的情况。 我们的 Web 应用程序始终以同一数据库用户身份运行,但使用应用程序跟踪和控制的不同逻辑用户。

我们通常将逻辑用户ID作为参数传递到每个存储过程中。 为了跟踪删除,我们通常不删除该行,只是将状态标记为已删除,并相应地设置 LastChgID 和 LastChgDate 字段。 对于重要的表,我们保留审核日志(每个更改状态的副本),我们使用上述方法,并且触发器将行复制到审核表,LastChgID 已经正确设置,触发器不需要担心关于获取 ID。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文