This can be an important query for your while debugging slowness of SQL server. This will help you find currently running SQL queries on SQL Server. You can find which queries are running from a long time and utilizing CPU.
To run this query, start SQL Server Management Studio, Open New Query window and copy below query in it. Now click on Execute button to run this query.
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.
6 Comments
This is a really useful query, is it possible to add the user that has run the query? Be it server log in name or the PC they are running it from?
Knowing the query is really useful but when you have 50+ users narrowing it down to user would take it to the next level
Τhis paragraph іs really a pleasant one it helps neѡ weeb uѕers, who аre wishing fߋr blogging.
Adding the following condition prevents the SQL from returning the current SQL in the results.
WHERE req.session_id != @@SPID
worked
A great technique to Find Currently Running Query in SQL Server. By the way, I have pleased to read the entirety of the post as mentioned above in detail. Thanks!
Thank you soo much…. It helps me alot to debug SQL Server slowness…. I found multiple SQL queries were running from a long time and causing 100% cpu uses…..