SELECT A.session_id, B.text
FROM sys.dm_exec_connections A
CROSS APPLY sys.dm_exec_sql_text(most_recent_sql_handle) B
SELECT
ISNULL(D.text, '') AS SQLStatement,
A.Session_ID SPID,
ISNULL(B.status,A.status) AS [Status],
A.login_name AS [Login],
ISNULL(A.host_name, ' .') AS HostName,
ISNULL(CAST(C.BlkBy AS varchar(10)), ' .') AS BlkBy,
DB_NAME(B.Database_ID) AS DBName,
B.command,
ISNULL(B.cpu_time, A.cpu_time) AS CPUTime,
ISNULL((B.reads + B.writes),(A.reads + A.writes)) AS DiskIO,
A.last_request_start_time AS LastBatch,
ISNULL(A.program_name, '') AS ProgramName,
ISNULL(A.client_interface_name, '') AS ClientInterfaceName
FROM sys.dm_exec_sessions A
LEFT OUTER JOIN sys.dm_exec_requests B ON A.session_id = B.session_id
LEFT OUTER JOIN (
SELECT A.request_session_id SPID, B.blocking_session_id BlkBy
FROM sys.dm_tran_locks A
INNER JOIN sys.dm_os_waiting_tasks B ON A.lock_owner_address = B.resource_address
) C ON A.Session_ID = C.SPID
OUTER APPLY sys.dm_exec_sql_text(B.sql_handle) D
'SQL Server > SQL Server Tip & Tech' 카테고리의 다른 글
FOR XML PATH Concatenation을 사용하는 재치있는 방법 (3) | 2008.07.07 |
---|---|
sp_procedure_params_rowset (2) | 2008.07.07 |
데이터베이스 명명 규칙 - Database Naming Conventions (3) | 2008.05.14 |
Windows Vista에 SQL 2005 Reporting Service 설치 (0) | 2008.03.27 |
테이블 정보 조회 SP (2) | 2008.02.29 |