如何获取触发器触发时的sql查询,最多n级?

发布于 2024-09-26 18:24:24 字数 868 浏览 1 评论 0原文

我想列出在 '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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨离汐 2024-10-03 18:24:24

如果您使用的是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文