How do I find long running queries in SQL server with process ID, Process name, login time, user, start time, and duration?

188    Asked by diashrinidhi in SQL Server , Asked on Jul 26, 2023

 Please help me to get the details for a long running query. ProcessID, process name, database, host, user, process login time, query start time and query duration. What is the method to get long running queries in sql server? I want a query or the SP that fetches me this data.

Answered by dia shrinidhi

 A tool sp_wholsActive is there to view what’s running when you launch the script or you can execute it in loops to observe certain action, like slow queries. If you wish to run a loop see this, How to Log Activity using sp_whoisactive in a Loop to detect slow queries. You can also utilize DMV’s to fetch the slowest queries and take action. You can also deploy the queries to get the most lengthy queries. You can also use the dm_exec_query_stats to include extra data or combine with others to retrieve more data. Make sure that DMV’s are cleared off and refreshed every time the server gets started.


The below-mentioned steps can be used to get the long running query in SQL server

Choose a distinct top 20.
est.TExt AS QUERY,
Db_name(dbid),
Eqs.execution_count AS EXEC_CNT,
Eqs.max_elapsed_time AS MAX_ELAPSED_TIME,
ISNULL (eqs.total_elapsed_time/NULLIF (eqs.execution_count,0),0) AS AVG_ELAPSED_TIME,
Eqs.creation_time AS CREATION_TIME,

The SQL Server Online Training offered at JanBask Training gives an experience like offline classes and prepares the students by covering the core concepts in MS SQL server certification making them ready to face the competitive job market. The students are also saved from the burden of traveling to physical locations to take classes. JanBask Training also aims to teach the wise methods of how the databases are generated and controlled in the business.



Your Answer

Interviews

Parent Categories