如何在SQL Server中查找当前运行的查询

这可能是调试SQL Server慢速时的重要查询。 这将帮助您在SQL Server上查找当前运行的SQL查询。 您可以从长时间查找哪些查询运行并使用CPU。

要运行此查询,启动SQL Server Management Studio,打开新建查询窗口并在其中复制下面的查询。 现在点击执行按钮运行这个查询。

SELECT sqltext.TEXT, req.session_id, req.status, req.start_time, req.command, req.cpu_time, req.total_elapsed_time FROM sys.dm_exec_requests req CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext
1
2
3
4
5
6
7
8
9
SELECT sqltext. TEXT ,
req.session_id,
req.status,
req.start_time,
req.command,
req.cpu_time,
req.total_elapsed_time
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext

Run the above query using SQL server management studio. The result will be different than below screenshot.

Output Details:

TEXT: The query is being executed.
session_id: Session id assigned to query. We can use this id to kill this query
status: Current status of the query
Start_time: The time query was started.

Share on Facebook Share
0
Share on Twitter Tweet
0
Share on Google Plus Share
0
Share on Pinterest Share
0
Share on Linkedin Share
0
Share on Digg Share
赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏