SQL Server 存储过程版本控制-DDL触发器
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL Server 存储过程版本控制-DDL触发器相关的知识,希望对你有一定的参考价值。
存储过程版本控制-DDL触发器
–参考:存储过程版本控制
CREATE TABLE [dbo].[ChangeLog](
[LogId] [int] IDENTITY(1,1) NOT NULL,
[DatabaseName] [varchar] (256) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[EventType] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[ObjectName] [varchar](256) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[ObjectType] [varchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[SqlCommand] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[EventDate] [datetime] NOT NULL CONSTRAINT [DF_EventsLog_EventDate] DEFAULT (getdate()),
[LoginName] [varchar](256) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[IP] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
ALTER trigger backup_objects
on ALL SERVER –all server 所有数据库上的操作。database:当前数据库的操作。On用来指定作用域
for create_procedure, alter_procedure, drop_procedure,
create_table, alter_table, drop_table,create_view, alter_view, drop_view,
create_function, alter_function, drop_function
as
set nocount on
declare @data xml set @data = EVENTDATA()
insert into BRM_TEST.dbo.changelog(databasename, eventtype, objectname, objecttype, sqlcommand, loginname,IP)
values( @data.value(‘(/EVENT_INSTANCE/DatabaseName)[1]‘, ‘varchar(256)‘),
@data.value(‘(/EVENT_INSTANCE/EventType)[1]‘, ‘varchar(50)‘),
@data.value(‘(/EVENT_INSTANCE/ObjectName)[1]‘, ‘varchar(256)‘),
@data.value(‘(/EVENT_INSTANCE/ObjectType)[1]‘, ‘varchar(25)‘),
@data.value(‘(/EVENT_INSTANCE/TSQLCommand)[1]‘, ‘varchar(max)‘),
@data.value(‘(/EVENT_INSTANCE/LoginName)[1]‘, ‘varchar(256)‘),
CONVERT(VARCHAR(50),CONNECTIONPROPERTY(‘client_net_address‘) ) )
GO
–DDL触发器http://msdn.microsoft.com/zh-cn/library/ms175941.aspx
–查看服务器级别的触发器
SELECT TOP 50 * FROM sys.server_triggers
–查看服务器级别的触发器的定义
SELECT * FROM sys.server_sql_modules
–查看激发触发器的数据库事件的信息
SELECT TOP 50 * FROM sys.server_trigger_events
–删除服务器上的DDL触发器
DROP TRIGGER backup_objects ON ALL SERVER
–失效DDL触发器
DISABLE TRIGGER backup_objects ON ALL SERVER
–获取有关数据库范围内的触发器的信息
SELECT * FROM sys.triggers
–获取有关激发触发器的数据库事件的信息
SELECT * FROM sys.trigger_events
–查看数据库范围内的触发器的定义
SELECT * FROM sys.sql_modules
–删除当前数据库上的DDL触发器
DROP TRIGGER backup_objects ON DATABASE
以上是关于SQL Server 存储过程版本控制-DDL触发器的主要内容,如果未能解决你的问题,请参考以下文章