Microsoft SQL Server 2012 管理 (2): Auditing

-- Demostratin 2A (Using SQL Server Audit)
-- Step 1: Use the master database
USE master;
GO

-- Step 2: Create a SQL Server Audit and define tis target as
-- application log
Create Server Audit MarketDevLog
To Application_log
With (QUEUE_DELAY = 1000, ON_FAILURE = CONTINUE)
GO

-- Step 3: Change to the MarketDev database
USE MarketDev;
GO

-- Step 4: Create a database audit specification for SELECT
-- activity on the Marketing schema
CREATE DATABASE AUDIT SPECIFICATION MrketingSelectSpec
    FOR SERVER AUDIT MarketDevLog
    ADD (SELECT ON SCHEMA::Marketing BY public);
GO

-- Step 5: Query the sys.server_audits system view.
-- Scroll to the right and note the available columns.
-- particular, note the is_state_enabled column.

SELECT * FROM sys.server_audits;
GO

-- Step 6: Change to master database
USE master;
GO

-- Step 7: Enable the server audit
ALTER SERVER AUDIT MarketDevLog WITH (STATE=ON);
GO

-- Step 8: Change to MarketDev database
USE MarketDev;
GO

-- Step 9: Enable the MarketingSelectSpec audit specification
ALTER DATABASE AUDIT SPECIFICATION MarketingSelectSpec
    WITH (STATE = ON);

-- Step 10: Query the sys.server_audits and
-- sys.database_audit_specifications and
-- sys.database_audit_specification_details system view
-- Note that the audit is now started and scroll to
-- see the details provided for the audit specification

SELECT * FROM sys.server_audits;
SELECT * FROM sys.database_audit_specifications;
SELECT * FROM sys.database_audit_specification_details;
GO

-- Step 11: Geenerate an auditable event by querying a table
-- in the Marketing schema. Also execute a query
-- that should not be audited.

SELECT * FROM Marketing.PostalCode;
GO
SELECT * FROM DirectMarketing.City;
GO

-- Step 12: Check the contents of the Application log
-- (Do this by Start, Right-click My Computer, then
-- Expand Diagnostics, Event Viewer, and Windows Logs
-- click Application. Click on each of the MSSQLSERVER
-- the upper pane For each evetn, click on the detail
-- the lower pane and review the contents). the close
-- management windows.

-- Step 13: Change to the master database
USE master;
GO

-- Step 14: Disable the server audit
ALTER SERVER AUDIT MarketDevLog WITH (STATE=OFF);
GO

-- Step 15: Change to the MarketDev database
USE MarketDev;
GO

-- Step 16: Disable the MarketingSelectSpec audit specification
ALTER DATABASE AUDIT SPECIFICATION MarketingSelectSpec
    WITH (STATE = OFF);
时间: 2024-07-29 22:14:17

Microsoft SQL Server 2012 管理 (2): Auditing的相关文章

Microsoft SQL Server 2012 管理 (1): 安装配置SQL Server 重点

SQL Server 可以在实例,数据库,列,查询分别指定排序规则 /* Module 1 - working with Clollations */ -- 1.1 Obtain the Instance Collation from the GUI --Create a Database without specifying a specific Collation Create Database UnspecifiedCollationDB; GO -- Use the statement

Microsoft SQL Server 2012 管理 (2): 实例与数据库管理

1.加密数据库 /* Module 2 Implementing Transparent Data Encryption */ -- 2.1 Create DataBase Master Key USE Master; GO Create Master Key Encryption By Password='[email protected]' -- The password above must adhere to the windows password policy -- could al

Querying Microsoft SQL Server 2012 读书笔记:查询和管理XML数据 1 -使用FOR XML返回XML结果集

原文:Querying Microsoft SQL Server 2012 读书笔记:查询和管理XML数据 1 -使用FOR XML返回XML结果集 XML 介绍 <CustomersOrders> <Customer custid="1" companyname="Customer NRZBB"> <Order orderid="10692" orderdate="2007-10-03T00:00:00&

Querying Microsoft SQL Server 2012 读书笔记:查询和管理XML数据 2 -使用XQuery 查询XML数据

原文:Querying Microsoft SQL Server 2012 读书笔记:查询和管理XML数据 2 -使用XQuery 查询XML数据 XQuery 是一个浏览/返回XML实例的标准语言. 它比老的只能简单处理节点的XPath表达式更丰富. 你可以同XPath一样使用.或是遍历所有节点,塑造XML实例的返回等. 作为一个查询语言, 你需要一个查询处理引擎. SQL Server 数据库通过XML数据类型方法的T-SQL 语句来处理XQuery. SQL Server 并不支持所有的X

【转】Microsoft&#174; SQL Server&#174; 2012 Performance Dashboard Reports

http://www.cnblogs.com/shanyou/archive/2013/02/12/2910232.html SQL Server Performance Dashboard Reports是一组Reporting Services的报表,和SQL Server Management Studio中所介绍的报表一起使用.这些报表允许数据库管理员快速地确定他们的系统中是否存在瓶颈,瓶颈是否正在发生,捕获这些附加的诊断数据可能会对解决问题更有帮助.例如,系统正在等待disk IO,这

跟我一起学Microsoft SQL Server 2012 Internals(3.3)

目录 目录 正确扩展与收缩SQL Server的数据database文件 参考资料 正确扩展与收缩SQL Server的数据(database)文件 在创建MS SQL Server数据库后,我们会调整一个重要选项,即数据文件与日志文件的增长方式.同时MS SQL Server可在必要时,收缩数据文件与日志文件的大小,但个人不建议做此操作. 下图所示是通过SSMS设置数据库文件的自动增长方式: 个人建议初始时给予足够的数据与日志空间,然后设置按固定MB的大小自动增长.若按图所示设置以百分比方式增

Microsoft SQL Server 2012 R2部署安装

SQL Server 的安装相对于其他服务来说还是比较简单的,插入光盘,点击"Setup"打开"SQL Server安装中心",在安装中心界面我们可以通过"计划""安装""维护""工具""资源""高级""选项"进行系统安装,信息查看以及系统设置,首先,点击"硬件和软件要求"来查看是否支持最低软硬件要求配置,在

Microsoft SQL Server 2012 附加数据库

今天闲来无事想看看以前的一个老旧的数据库,用Microsoft SQL Server 2012 附加数据库,结果悲剧了,出了一堆的错误,所幸经过几次尝试后终于解决了问题,错误信息如下,解决的方法也简单,以管理员身份运行SQL Server Management Studio,然后再附加数据库即可,写出来供大家参考. TITLE: Microsoft SQL Server Management Studio ------------------------------ Attach databas

跟我一起学Microsoft SQL Server 2012 Internals(3.2)

目录 目录 正确认识SQL Server数据库文件 创建一个数据库database 参考资料 正确认识SQL Server数据库文件 MS SQL Server的数据库文件可分成如下2类: 数据文件(.mdf或.ndf) 事务日志文件(.ldf) 其中"数据文件"可分为:主数据文件(Primary data files,即.mdf)与次数据文件(Secondary data files,即.ndf) 我们可通过目录视图sys.database_files查看数据库文件的相关信息 --查