A Better sp_who2 using DMVs (sp_who3)
2010-04-06 10:43
579 查看
Thefollowingcodegeneratesthesameinformationfoundinsp_who2,alongwithsomeadditionaltroubleshootinginformation.ItalsocontainstheSQLStatementbeingrun,soinsteadofhavingtoexecuteaseparateDBCCINPUTBUFFER,thestatementbeingexecutedisshownintheresults.
Unlikesp_who2,sp_who3onlyshowssessionsthathaveacurrentexecutingrequest.
Whatisalsoshownisthereadsandwritesforthecurrentcommand,alongwiththenumberofreadsandwritesfortheentireSPID.Italsoshowstheprotocolbeingused(TCP,NamedPipes,orSharedMemory).
Unlikesp_who2,sp_who3onlyshowssessionsthathaveacurrentexecutingrequest.
Whatisalsoshownisthereadsandwritesforthecurrentcommand,alongwiththenumberofreadsandwritesfortheentireSPID.Italsoshowstheprotocolbeingused(TCP,NamedPipes,orSharedMemory).
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_requestser |
OUTER APPLYsys.dm_exec_sql_text(er.sql_handle)st |
LEFT JOIN sys.dm_exec_sessionsses |
ON ses.session_id=er.session_id |
LEFT JOIN sys.dm_exec_connectionscon |
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 |
相关文章推荐
- sp_who, sp_who2和sp_who3
- Transact-SQL参考: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
- Transact-SQL参考: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
- sp_who, sp_who2和sp_who3
- sp_who2 status
- SQLSERVER 中sp_who, sp_who2和sp_who3
- [SQL Server] sp_who, sp_who2和sp_who3
- SQLSERVER 执行sp_who2 显示的LastBatch列时间显示不正确
- 记录一个统计MSSQL TABLE资料量的sp
- sp_executesql接收返回多个参数实例
- oracle自动创建时间分区SP
- sp_MSforeachtable 与 sp_MSforeachdb