--我使用以下过程:
使用 [主]
去
创建过程 [dbo].[sp_who3]
作为
设置无计数
声明@LoginName varchar(128)
声明 @AppName varchar(128)
选择 [SPID] = s.[spid]
, [CPU] = s.[cpu]
, [Physical_IO] = s.[physical_io]
, [封锁] = s.[封锁]
, [LoginName] = CONVERT([sysname], RTRIM(s.[Loginame]))
, [数据库] = d.[名称]
, [AppName] = s.[program_name]
, [主机名] = s.[主机名]
, [状态] = s.[状态]
, [Cmd] = s.[cmd]
, [最后一批] = s.[last_batch]
, [杀死命令] = '杀死' + CAST(s.[spid] AS varchar(10))
, [缓冲区命令] = 'DBCC InputBuffer(' + CAST(s.[spid] AS varchar(10))
+ ')'
FROM [master].[dbo].[sysprocesses] s WITH(NOLOCK)
加入 [master].[sys].[databases] d WITH(NOLOCK)
ON s.[dbid] = d.[database_id]
WHERE s.[状态] '背景'
AND s.[spid] @@SPID --@CurrentSpid@
ORDER BY s.[blocked] DESC, s.[physical_io] DESC, s.[cpu] DESC, CONVERT([sysname], RTRIM(s.[Loginame]))
开始
设置事务隔离级别读取未提交
SELECT [Spid] = er.[session_Id]
, [ECID] = sp.[ECID]
, [数据库] = DB_NAME(sp.[dbid])
, [用户] = [nt_username]
, [状态] = 呃.[状态]
, [等待] = [等待类型]
, [个别查询] = SUBSTRING(qt.[text], er.[statement_start_offset] / 2, (CASE WHEN er.[statement_end_offset] = - 1 THEN LEN(CONVERT(VARCHAR(MAX), qt.[text])) * 2
ELSE er.[statement_end_offset] END - er.[statement_start_offset]) / 2)
, [父查询] = qt.[文本]
, [程序] = sp.[程序名称]
, [主机名] = sp.[主机名]
, [域] = sp.[nt_domain]
, [开始时间] = 呃。[开始时间]
FROM [sys].[dm_exec_requests] er WITH(NOLOCK)
INNER JOIN [sys].[sysprocesses] sp WITH(NOLOCK)
ON er.[session_id] = sp.[spid]
交叉应用 [sys].[dm_exec_sql_text](er.[sql_handle]) qt
WHERE er.[session_Id] > 50 -- 忽略系统 spid。
AND er.[session_Id] NOT IN (@@SPID) -- 忽略当前语句。
ORDER BY er.[session_Id], sp.[ECID]
结尾
去