SQL Server 根据spid查询执行的sql语句

sp_who2查询出的spid
根据spid来查询执行的SQL语句

select er.session_id,CAST(csql.text AS varchar(255)) AS CallingSQL
from master.sys.dm_exec_requests er
WITH (NOLOCK)
       CROSS APPLY MASTER.sys.fn_get_sql (er.sql_handle) csql
where er.session_id =@spid

猜你喜欢

转载自blog.csdn.net/InJra_p/article/details/89949519