如何查看数据库变更记录
第一步:建库建表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
CREATE DATABASE AuditDB GO USE [AuditDB] GO IF EXISTS ( SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N '[DF__DDLEvents__Event__7E6CC920]' ) AND type = 'D' ) BEGIN ALTER TABLE [dbo].[DDLEvents] DROP CONSTRAINT [DF__DDLEvents__Event__7E6CC920] END GO USE [AuditDB] GO /****** Object: Table [dbo].[DDLEvents] Script Date : 10/29/2012 17:29:26 ******/ IF EXISTS ( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N '[dbo].[DDLEvents]' ) AND type in (N 'U' )) DROP TABLE [dbo].[DDLEvents] GO USE [AuditDB] GO /****** Object: Table [dbo].[DDLEvents] Script Date : 10/29/2012 17:29:26 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[DDLEvents]( [EventDate] [datetime] NOT NULL , [EventType] [nvarchar](64) NULL , [EventDDL] [nvarchar]( max ) NULL , [EventXML] [xml] NULL , [DatabaseName] [nvarchar](255) NULL , [SchemaName] [nvarchar](255) NULL , [ObjectName] [nvarchar](255) NULL , [HostName] [ varchar ](64) NULL , [IPAddress] [ varchar ](32) NULL , [ProgramName] [nvarchar](255) NULL , [LoginName] [nvarchar](255) NULL ) ON [ PRIMARY ] GO SET ANSI_PADDING OFF GO ALTER TABLE [dbo].[DDLEvents] ADD DEFAULT (getdate()) FOR [EventDate] GO 二步:在需要监控的库上执行这个脚本,对DDL操作会记录在第一步中的库中
|