Anyway to create a SQL Server DDL trigger for quot;SELECTquot; statements?(无论如何,为“SELECT创建一个 SQL Server DDL 触发器;声明?)
问题描述
我正在处理一些敏感的会计表,我想审计在该表上执行的任何 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.
我在 BOL(在线图书) 与 SELECT 语句有关.DML 触发器仅用于 INSERT、UPDATE 和 DELETE.
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.
是否可以通过 SELECT 语句记录谁访问了表和视图?
Is it possible to log who accesses table and views through SELECT statement?
推荐答案
您有 3 个选择:
- 如果您想登录(并删除表权限),则允许通过存储过程进行访问
- 如果您想限制并保持直接"访问,请将表格隐藏在视图后面
- 运行永久跟踪
我会选择选项 1 或 2,因为它们是您的应用程序的一部分并且是独立的.
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...
查看示例:
CREATE VIEW dbo.MyTableMask
AS
SELECT *
FROM
MyTable
CROSS JOIN
(SELECT 1 FROM SecurityList WHERE name = SUSER_SNAME())
--WHERE could use NOT EXISTS too with table
GO
这篇关于无论如何,为“SELECT"创建一个 SQL Server DDL 触发器;声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无论如何,为“SELECT"创建一个 SQL Server DDL 触发器;声明?
基础教程推荐
- oracle区分大小写的原因? 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 在多列上分布任意行 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
