我正在使用触发器来跟踪 DDL 更改,但是当我从 SQL Server Management Studio 更改列名时,触发器不起作用?
create TRIGGER trgLogDDLEvent ON DATABASE
FOR DDL_DATABASE_LEVEL_EVENTS
FOR
AS
DECLARE @data XML
SET @data = EVENTDATA()
IF @data.value('(/EVENT_INSTANCE/EventType)[1]', 'nvarchar(100)')
<> 'CREATE_STATISTICS'
INSERT INTO db_trc_DDLChangeLog
(
EventType,
ObjectName,
ObjectType,
tsql,
RecDate,
HostName
)
VALUES (
@data.value('(/EVENT_INSTANCE/EventType)[1]',
'nvarchar(100)'),
@data.value('(/EVENT_INSTANCE/ObjectName)[1]',
'nvarchar(100)'),
@data.value('(/EVENT_INSTANCE/ObjectType)[1]',
'nvarchar(100)'),
@data.value('(/EVENT_INSTANCE/TSQLCommand)[1]',
'nvarchar(max)'),
getdate(),
HOST_NAME()
) ;
GO
--select * from db_trc_DDLChangeLog
--create table db_trc_DDLChangeLog
--(
--EventType varchar(max),
--ObjectName varchar(max),
--ObjectType varchar(max),
--tsql varchar(max),
--RecDate datetime,
--HostName varchar(max)
--)