您可以创建一个 DDL 触发器来记录ALTER_PROCEDURE
如下事件:
CREATE TABLE dbo.AlterLog(EventType VARCHAR(50)
, ObjectName VARCHAR(256)
, ObjectType VARCHAR(25)
, TSQLCommand VARCHAR(MAX)
, LoginName VARCHAR(256)
);
GO
CREATE TRIGGER AlterProcs
ON DATABASE
FOR ALTER_PROCEDURE
AS
SET NOCOUNT ON;
DECLARE @data XML
SET @data = EVENTDATA()
INSERT INTO dbo.AlterLog(EventType, ObjectName, ObjectType, TSQLCommand, LoginName)
VALUES(@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)')
)
GO