如何获取触发器触发时的sql查询,最多n级?
我想列出在 'AFTER UPDATE TRIGGER' 触发之前执行的查询,最多可达 n 个级别。列表将在触发器本身内完成。 n 可以是 4 或更小。
任何指针或列表是否可以通过任何其他方式完成会有帮助吗?
如果有bug,我必须调试前端和后端。
--编辑--
实际上,每次都会将单元格更新为空。我必须追踪它。这种情况很少发生。
--编辑--
或者说如何获取用户执行的最后n个查询。
- 编辑 - 我做了如下:
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
-- 之后的代码似乎正在工作,因为完整的代码为所有用户提供了执行查询的代码。我评论它们是因为它对服务器来说很重。
连接问题在这里 SQL 单元明智触发器 (哪个流程出现在发布为“..触发,最多 n 级?”的问题之前?)
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 because 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?')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是 SQL Server 2008,则可以使用扩展事件来获取整个 TSQL 调用堆栈。有关示例代码,请参阅我的回答。
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.