我为每个表插入、更新、删除触发器以记录操作。我正在从删除、插入并将这些数据包装到 xml 之前和之后检索数据。但是有些日志不能显示之前和更新值。我的sql语句是:
USE [cop]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[Delete] ON [dbo].[Seanslar]
AFTER DELETE
AS
BEGIN
SET NOCOUNT ON
DECLARE @deleted AS XML
SET @deleted = (select * from deleted for xml AUTO, ELEMENTS XSINIL)
DECLARE @logIslem TINYINT
SET @logIslem = 3
DECLARE @tableName VARCHAR(200)
SELECT @tableName = OBJECT_SCHEMA_NAME( parent_id ) + '.' + OBJECT_NAME( parent_id )
FROM sys.triggers
WHERE object_id = @@PROCID
DECLARE @xmlToChar NVARCHAR(MAX)
SET @xmlToChar = CAST(@deleted AS nvarchar(MAX))
IF LEN(@xmlToChar)<10
BEGIN
IF EXISTS(select * from deleted)
select @xmlToChar = CAST(seans_id AS NVARCHAR(MAX)) from deleted
ELSE
SET @xmlToChar = 'Deleted is empty!'
END
DECLARE @allXml AS XML
SET @allXml = '<'+@tableName+'>'+ @xmlToChar +'</'+@tableName+'>'
INSERT INTO [dbo].[Logla]
([logIslem], [trgKullanici_id], [tabloAdi], [logXml])
VALUES
(@logIslem, SUSER_NAME(), @tableName, @allXml)
END
有什么方法可以学习在触发器中执行的“sql语句”?