无论如何,为“SELECT”创建 SQL Server DDL 触发器声明?
我正在处理一些敏感的会计表,我想审核在表上执行的任何 SELECT
语句或与其关联的任何视图。
我在 BOL(联机丛书)上没有找到任何 DDL 事件与 SELECT 语句有关的任何事情。 DML 触发器仅适用于 INSERT
、UPDATE
和 DELETE
。
是否可以通过 SELECT 语句记录谁访问表和视图?
I am dealing with some sensitive Accounting tables and I would like to audit any SELECT
statement executed on the table or any views associated with them.
I did not find any DDL Events on BOL (Books Online) that had anything to do with SELECT
statement.
And DML triggers are for INSERT
, UPDATE
and DELETE
only.
Is it possible to log who accesses table and views through SELECT
statement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
是的,可以通过在事件通知上创建="http://msdn.microsoft.com/en-us/library/ms179332(SQL.90).aspx" rel="noreferrer">AUDIT_DATABASE_OBJECT_ACCESS_EVENT 事件。然而,做这样的事情的成本将是巨大的。
最好使用审核基础架构,或使用自定义访问包装器正如 gbn 所建议的那样。
Yes, it is possible by creating an Event Notification on the AUDIT_DATABASE_OBJECT_ACCESS_EVENT event. The cost of doing something like this would be overwhelming though.
It is much better to use the audit infrastructure, or using custom access wrapper as gbn recommends.
您有 3 个选项:
我会选择选项 1 或2 因为它们是您的应用程序的一部分并且是独立的。
尽管如此,这听起来确实有点晚了开始记录:对表的访问应该预先受到限制。
此外,如果最终用户不直接纠正(例如通过网络服务器或服务帐户),任何解决方案都会失败。除非您使用存储过程发送最终用户名...
查看示例:
You have 3 options:
I'd go for options 1 or 2 because they are part of your application and self contained.
Although, this does sound a bit late to start logging: access to the table should have been restricted up front.
Also, any solution fails if end users do not correct directly (eg via web server or service account). Unless you use stored procs to send in the end user name...
View example:
我刚刚为你添加了一些代码。该代码创建服务器审核、针对选定活动的数据库审核,最后使用 sys.fn_get_audit_file 从文件中检索信息。您必须为每个表单独执行此操作。如果您想要更自动化的查询,您可以使用其他工具,例如 Apex SQL Audit 或您喜欢的其他第三方工具。
I just added some code for you. The code creates a server audit, a database audit for select activities and finally the sys.fn_get_audit_file is used to retrieve the information from the file. You have to do that individually for each table. If you want a more automated query, you can use other tools like Apex SQL Audit or other third party tool of your preference.
SQL Server 2008 审核也许能够捕获它。除此之外,Profiler/Tracing 是 SQL Server 中唯一可以做到这一点的东西。
SQL Server 2008 Auditing may be able to capture it. Other than that, Profiler/Tracing is the only thing in SQL Server that can do it.
编辑:使用 SQL Server Profiler 查看和分析跟踪
Edit : Viewing and Analyzing Traces with SQL Server Profiler