开发者

How to get the sql queries when trigger was triggered, upto n levels?

开发者 https://www.devze.com 2023-01-19 06:09 出处:网络
I want to list down the queries executed before the \'AFTER UPDATE TRIGGER\' triggered up to n levels. The listing will be done within the TRIGGER itself.

I want to list down the queries executed before the 'AFTER UPDATE TRIGGER' triggered up to n levels. The listing will be done within the TRIGGER itself. The n can be 4 or less.

Any pointer or if listing can be done by any other way will be helpful?

I have to debug the front-end and back-end if bug is there.

--Edit--

Actually a cell is being update each time as empty. I have to track it down. It happens very rarely.

--Edit--

Or say how to get the last n queries executed by the user.

--Edit-- I did as follows:

SELECT top(15) dest.text AS [Query]
        FROM sys.dm_exec_query_stats AS deqs
        CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
          --inner join  sys.sysprocesses
          -- on sys.sysprocesses.sql_handle=deqs.sql_handle
        ORDER BY deqs.last_execution_time DESC

The code after -- seems to be working where as the full code gives the all users code executed queries. I comented them beca开发者_运维百科use It is heavy for the server.

The connecting Question is here SQL cell wise trigger (Which is the flow comes before the issue posted as ' .. triggered, upto n levels?')


If you are on SQL Server 2008 you can use extended events to get the whole TSQL call stack. See my answer here for example code.

0

精彩评论

暂无评论...
验证码 换一张
取 消