sp_who, sp_who2和sp_who3
2012-12-12 18:40
363 查看
sp_who, sp_who2和sp_who3
sp_who可以返回如下信息: (可选参数LoginName, 或active代表活动会话数)
Spid (系统进程ID)
status (进程状态)
loginame (用户登录名)
hostname(用户主机名)
blk (阻塞进程的SPID)
dbname (进程正在使用的数据库名)
Cmd (当前正在执行的命令类型)
sp_who2除了显示上面sp_who的输出信息外,还显示下面的信息: (可选参数LoginName, 或active代表活动会话数)
CPUTime (进程占用的总CPU时间)
DiskIO (进程对磁盘读的总次数)
LastBatch (客户最后一次调用存储过程或者执行查询的时间)
ProgramName (用来初始化连接的应用程序名称,或者主机名)
sp_who3是某牛人自定义的存储过程,(可选参数spid),显示“非系统会话,且是活动的会话”的详细情况。
CREATE PROCEDURE sp_who3
( @SessionID INT = NULL )
AS
BEGIN
SELECT
SPID = er.session_id
,STATUS = ses.STATUS
,[Login] = ses.login_name
,Host = ses.host_name
,BlkBy = er.blocking_session_id
,DBName = DB_Name(er.database_id)
,CommandType = er.command
,SQLStatement = st.text
,ObjectName = OBJECT_NAME(st.objectid)
,ElapsedMS = er.total_elapsed_time
,CPUTime = er.cpu_time
,IOReads = er.logical_reads + er.reads
,IOWrites = er.writes
,LastWaitType = er.last_wait_type
,StartTime = er.start_time
,Protocol = con.net_transport
,ConnectionWrites = con.num_writes
,ConnectionReads = con.num_reads
,ClientAddress = con.client_net_address
,Authentication = con.auth_scheme
FROM sys.dm_exec_requests er
OUTER APPLY sys.dm_exec_sql_text(er.sql_handle) st
LEFT JOIN sys.dm_exec_sessions ses
ON ses.session_id = er.session_id
LEFT JOIN sys.dm_exec_connections con
ON con.session_id = ses.session_id
WHERE er.session_id > 50
AND @SessionID IS NULL OR er.session_id = @SessionID
ORDER BY
er.blocking_session_id DESC
,er.session_id
END
GO
sp_who可以返回如下信息: (可选参数LoginName, 或active代表活动会话数)
Spid (系统进程ID)
status (进程状态)
loginame (用户登录名)
hostname(用户主机名)
blk (阻塞进程的SPID)
dbname (进程正在使用的数据库名)
Cmd (当前正在执行的命令类型)
sp_who2除了显示上面sp_who的输出信息外,还显示下面的信息: (可选参数LoginName, 或active代表活动会话数)
CPUTime (进程占用的总CPU时间)
DiskIO (进程对磁盘读的总次数)
LastBatch (客户最后一次调用存储过程或者执行查询的时间)
ProgramName (用来初始化连接的应用程序名称,或者主机名)
sp_who3是某牛人自定义的存储过程,(可选参数spid),显示“非系统会话,且是活动的会话”的详细情况。
CREATE PROCEDURE sp_who3
( @SessionID INT = NULL )
AS
BEGIN
SELECT
SPID = er.session_id
,STATUS = ses.STATUS
,[Login] = ses.login_name
,Host = ses.host_name
,BlkBy = er.blocking_session_id
,DBName = DB_Name(er.database_id)
,CommandType = er.command
,SQLStatement = st.text
,ObjectName = OBJECT_NAME(st.objectid)
,ElapsedMS = er.total_elapsed_time
,CPUTime = er.cpu_time
,IOReads = er.logical_reads + er.reads
,IOWrites = er.writes
,LastWaitType = er.last_wait_type
,StartTime = er.start_time
,Protocol = con.net_transport
,ConnectionWrites = con.num_writes
,ConnectionReads = con.num_reads
,ClientAddress = con.client_net_address
,Authentication = con.auth_scheme
FROM sys.dm_exec_requests er
OUTER APPLY sys.dm_exec_sql_text(er.sql_handle) st
LEFT JOIN sys.dm_exec_sessions ses
ON ses.session_id = er.session_id
LEFT JOIN sys.dm_exec_connections con
ON con.session_id = ses.session_id
WHERE er.session_id > 50
AND @SessionID IS NULL OR er.session_id = @SessionID
ORDER BY
er.blocking_session_id DESC
,er.session_id
END
GO
相关文章推荐
- [SQL Server] sp_who, sp_who2和sp_who3
- sp_who, sp_who2和sp_who3
- Transact-SQL参考:sp_who、sp_who2和sp_who3
- [SQL Server] sp_who, sp_who2和sp_who3
- Transact-SQL参考:sp_who、sp_who2和sp_who3
- [SQL Server] sp_who, sp_who2和sp_who3
- sp_who, sp_who2和sp_who3
- [SQL Server] sp_who, sp_who2和sp_who3
- [SQL Server] sp_who, sp_who2和sp_who3
- sp_who, sp_who2和sp_who3
- [SQL Server] sp_who, sp_who2和sp_who3
- sp_who, sp_who2和sp_who3
- A Better sp_who2 using DMVs (sp_who3)
- SQLSERVER 中sp_who, sp_who2和sp_who3
- SqlServer 调优的几个关键的步骤--sp_lock,sp_who
- sp_who_lock
- SQLSERVER 执行sp_who2 显示的LastBatch列时间显示不正确
- 【SqlServer性能检测系列一】sp_who
- sp_who status means
- [SQL SERVER] 统计SQL用户连接情况(sp_who)