1. 程式人生 > 其它 >檢視當前執行的sql

檢視當前執行的sql

     SELECT TOP 100 t.hostname,
                t.loginame,
                percent_complete,
        [session_id] ,
        der.[request_id] ,
        [start_time] AS '開始時間' ,
        der.[status] AS '狀態' ,
        [command] AS '命令' ,
        dest.[text] AS 'sql語句' ,
        DB_NAME([database_id]) AS
'資料庫名' , [blocking_session_id] AS '正在阻塞其他會話的會話ID' , [wait_type] AS '等待資源型別' , [wait_time] AS '等待時間' , [wait_resource] AS '等待的資源' , [reads] AS '物理讀次數' , [writes] AS '寫次數' , [logical_reads] AS '邏輯讀次數' , [row_count] AS '返回結果行數', t.hostname, t.loginame
FROM sys.[dm_exec_requests] AS der CROSS APPLY sys.[dm_exec_sql_text](der.[sql_handle]) AS dest left JOIN sys.sysprocesses t ON t.spid=der.session_id WHERE [session_id] > 50 -- AND DB_NAME(der.[database_id]) = 'gposdb' ORDER BY [cpu_time] DESC