Using below Dynamic Management View
(DMV) query, you can view the queries which are currently running.
SELECT * FROM sys.dm_exec_requests
Each row represents a currently
running query.
Using below query, you can view most required details of the currently running queries.
Output columns of the query:
Output columns of the query:
Blocking Session ID, login Name, Data Base Name, Status, Query Statement, Duration, Wait Type, Query Plan, Complete Percentage (If applicable eg. Backups), Estimate Completion Time (If applicable eg. Backups), Host Name
WITH cte AS (
SELECT
r.session_id, r.request_id, r.database_id, t.objectid, t.[text], r.statement_start_offset/2
AS StatementStartOffset
, CASE WHEN r.statement_end_offset
> r.statement_start_offset
THEN r.statement_end_offset/2 ELSE LEN(t.[text]) END AS StatementEndOffset
, p.query_plan,CAST(getdate()-r.start_time as time) Duration
,percent_complete,
dateadd(second,estimated_completion_time/1000
, getdate()) as estimated_completion_time,R.status,r.wait_type
, getdate()) as estimated_completion_time,R.status,r.wait_type
FROM sys.dm_exec_requests r
CROSS APPLY sys.dm_exec_sql_text(r.[sql_handle]) t
OUTER APPLY sys.dm_exec_query_plan(r.plan_handle) p
WHERE r.[sql_handle] IS NOT NULL
), spaceUsage AS (
SELECT
session_id, request_id
, SUM(user_objects_alloc_page_count - user_objects_dealloc_page_count) / 128 AS UserObjMB
, SUM(internal_objects_alloc_page_count - internal_objects_dealloc_page_count) / 128 AS InternalObjMB
FROM sys.dm_db_task_space_usage
GROUP BY session_id,
request_id
)
SELECT
r.Session_id
,(SELECT DISTINCT MAX(blocking_session_id)
FROM Sys.dm_os_waiting_tasks
WHERE blocking_session_id IS
not NULL AND session_id = R.session_id) Blocking_Sid
, REPLACE(s.login_name,'NT AUTHORITY\','') login_name
, DB_NAME(r.database_id) AS DB_Name,R.Status
, DB_NAME(r.database_id) AS DB_Name,R.Status
, COALESCE('[' + OBJECT_SCHEMA_NAME(r.objectid, r.database_id) + '].[' + OBJECT_NAME(r.objectid, r.database_id) + ']'
, LEFT(LTRIM(r.[text]), 128)) AS Query_Batch
, LEFT(LTRIM(r.[text]), 128)) AS Query_Batch
, SUBSTRING(r.[text], r.StatementStartOffset
, r.StatementEndOffset - r.StatementStartOffset) AS Current_Statement
,Duration,r.Wait_Type , LEN(LEFT(r.[text], r.StatementStartOffset)) - LEN(REPLACE(LEFT(r.[text], r.StatementStartOffset), CHAR(10), '')) + 1 AS Line_Number
, r.StatementEndOffset - r.StatementStartOffset) AS Current_Statement
,Duration,r.Wait_Type , LEN(LEFT(r.[text], r.StatementStartOffset)) - LEN(REPLACE(LEFT(r.[text], r.StatementStartOffset), CHAR(10), '')) + 1 AS Line_Number
, u.UserObjMB AS [UserObjMB*], u.InternalObjMB, r.Query_Plan
,Percent_Complete,
Estimated_Completion_Time,S.[Host_Name]
FROM cte r
INNER JOIN sys.dm_exec_sessions s ON s.session_id = r.session_id
LEFT JOIN spaceUsage u ON
r.session_id =
u.session_id AND
r.request_id =
u.request_id
And also
you can use Activity Monitor to view currently running queries