--会话,连接,阻塞,线程
select *
from sys.sysprocesses
where spid = @@SPID
--类似于sys.sysprocesses
select *
from sys.dm_exec_sessions s
inner join sys.dm_exec_connections c
on s.session_id = c.session_id
left join sys.dm_exec_requests r
on r.session_id = c.session_id
where s.session_id > 50
--当前会话的线程数
select s.session_id,
r.connection_id,
r.request_id,
ot.os_thread_id
from sys.dm_exec_sessions s
inner join sys.dm_exec_connections c
on c.session_id = s.session_id
left join sys.dm_exec_requests r
on s.session_id = r.session_id
left join sys.dm_os_workers t
on r.task_address = t.task_address
left join sys.dm_os_threads ot
on ot.thread_address= t.thread_address
where s.session_id = @@SPID