Sqlserver在触发器里获取触发的语句

-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
 
begin
CREATE TABLE #T ( EVENTTYPE VARCHAR(20), PARAMETERS INT, EVENTINFO NText )
INSERT #T EXEC('DBCC INPUTBUFFER ('+@@SPID+')')
 
SELECT @host=[host_name],@log=login_name
FROM sys.dm_exec_sessions
WHERE session_id = @@SPID
Insert Into TableForExecSqlLog([Sql],DbTable,Var1,Var2)
select (select EVENTINFO From #T),'Truck',@host,@log From sys.dm_exec_sessions where session_id=@@SPID
Drop table #T
end

posted @ 2021-05-14 09:18  望着天的蜗牛  阅读(710)  评论(0编辑  收藏  举报