Sql Server中通过sql命令获取cpu占用及产生锁的sql(sqlserver默认端口)居然可以这样

随心笔谈2年前发布 编辑
164 0
🌐 经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用 点我优惠购买
🚀 拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多 点我优惠购买
🛡️ 稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少 点我优惠购买

SELECT
SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,((CASE statement_end_offset WHEN -1 THEN DATALENGTH(st.text) ELSE qs.statement_end_offset END – qs.statement_start_offset)/2) + 1) as statement_text
FROM sys.dm_exec_query_stats as qs CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as st where qs.sql_handle in (select distinct sql_handle from sys.dm_exec_requests where session_id in (SELECT request_session_id as Spid
FROM sys.dm_tran_locks l
LEFT JOIN sys.partitions p
ON l.resource_associated_entity_id=p.hobt_id
LEFT JOIN sys.indexes i
ON p.object_id=i.object_id
AND p.index_id=i.index_id
LEFT JOIN sys.objects o
ON p.object_id=o.object_id
LEFT JOIN sys.schemas s
ON o.schema_id=s.schema_id
LEFT JOIN sys.objects o2
ON l.resource_associated_entity_id=o2.object_id
LEFT JOIN sys.schemas s2
ON o2.schema_id=s2.schema_id
LEFT JOIN sys.databases db
ON l.resource_database_id=db.database_id
WHERE resource_database_id=DB_ID() and request_mode in (‘X’)
))

© 版权声明

相关文章