I am creating a trigger to track how procedure text has been ALTER
ed.
Inside a database DDL trigger,
it's possible to access current procedure Text through /EVENT_INSTANCE/TSQLCommand
.
Even after investigating EVENTDATA()
, it did not contain values for previous definition of procedure before ALTER
.
Is there a way to retrieve previous text like how it's possible to access deleted values in DML triggers using DELETED
table?
create trigger trgDDLAuditQuery
on database
for alter_procedure
as
begin
set nocount on;
declare @data xml
set @data = EVENTDATA()
insert dbo.tblQueryAudit(ObjectName, TSQLCommand)
select @data.value('(/EVENT_INSTANCE/ObjectName)[1]', 'nvarchar(256)'),
--; Only gets currently changed procedure text, not previous one
@data.value('(/EVENT_INSTANCE/TSQLCommand)[1]', 'nvarchar(max)')
end
GO