How to Identify a System Query

I am currently getting the details of executed queries from the table sys.dm_exec_query_stats. Is there any way to identify whether an executed query is a system query or not, using some information in sys.dm_exec_query_stats table or using some other methods

1

1 Answer

In sys.dm_exec_sessions there is a column named is_user_process. 0 means system process, 1 is user process. MSDN link here.

To show connection to your tables I post query that I am using for monitoring activity:

SELECT distinct 
        s.session_id,
        s.login_name,
        c.client_net_address,
        w.wait_duration_ms,
        w.wait_duration_ms/1000/60 as [min],
        w.wait_type,
        w.resource_address,
        w.blocking_session_id,
        w.resource_description,
        CAST (st.text as nvarchar(max)) AS [SQL Text],
        s.is_user_process
FROM sys.dm_exec_sessions S
LEFT JOIN sys.dm_exec_connections AS c ON S.session_id = c.session_id
LEFT JOIN sys.dm_exec_query_stats qs on c.most_recent_sql_handle = qs.sql_handle
INNER JOIN sys.dm_os_waiting_tasks AS w ON w.session_id = s.session_id
OUTER APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st
ORDER BY s.is_user_process DESC, w.wait_duration_ms DESC
4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest