SQL Server中查询CPU占用高的SQL语句

SQL Server中查询CPU占用高的情况,会用到sys.sysprocesses ,dm_exec_sessions ,dm_exec_requests

一、查看当前的数据库用户连接有多少

USE master

GO

SELECT * FROM sys.[sysprocesses] WHERE [spid]>50 --AND DB_NAME([dbid])='gposdb'

SELECT COUNT(*) FROM [sys].[dm_exec_sessions] WHERE [session_id]>50

二、选取前10个最耗CPU时间的会话

 
SQL 代码   复制
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句SELECT TOP 10
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句[session_id],
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句[request_id],
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句[start_time] AS '开始时间',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句[status] AS '状态',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句[command] AS '命令',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句dest.[text] AS 'sql语句',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句DB_NAME([database_id]) AS '数据库名',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句[blocking_session_id] AS '正在阻塞其他会话的会话ID',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句[wait_type] AS '等待资源类型',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句[wait_time] AS '等待时间',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句[wait_resource] AS '等待的资源',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句[reads] AS '物理读次数',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句[writes] AS '写次数',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句[logical_reads] AS '逻辑读次数',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句[row_count] AS '返回结果行数'
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句FROM sys.[dm_exec_requests] AS der
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句CROSS APPLY
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句sys.[dm_exec_sql_text](der.[sql_handle]) AS dest
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句WHERE [session_id]>50 AND DB_NAME(der.[database_id])='gposdb'
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句ORDER BY [cpu_time] DESC

三、查询前10个最耗CPU时间的SQL语句

 
SQL 代码   复制
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句--在SSMS里选择以文本格式显示结果
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句SELECT TOP 10
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句dest.[text] AS 'sql语句'
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句FROM sys.[dm_exec_requests] AS der
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句CROSS APPLY
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句sys.[dm_exec_sql_text](der.[sql_handle]) AS dest
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句WHERE [session_id]>50
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句ORDER BY [cpu_time] DESC
SQL Server中查询CPU占用高的SQL语句

四、查询会话中有多少个worker在等待 

 
SQL 代码   复制
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句SELECT TOP 10
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 [session_id],
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 [request_id],
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 [start_time] AS '开始时间',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 [status] AS '状态',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 [command] AS '命令',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 dest.[text] AS 'sql语句',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 DB_NAME([database_id]) AS '数据库名',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 [blocking_session_id] AS '正在阻塞其他会话的会话ID',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 der.[wait_type] AS '等待资源类型',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 [wait_time] AS '等待时间',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 [wait_resource] AS '等待的资源',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 [dows].[waiting_tasks_count] AS '当前正在进行等待的任务数',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 [reads] AS '物理读次数',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 [writes] AS '写次数',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 [logical_reads] AS '逻辑读次数',
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 [row_count] AS '返回结果行数'
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 FROM sys.[dm_exec_requests] AS der
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 INNER JOIN [sys].[dm_os_wait_stats] AS dows
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 ON der.[wait_type]=[dows].[wait_type] CROSS APPLY sys.[dm_exec_sql_text](der.[sql_handle]) AS dest WHERE [session_id]>50 ORDER BY [cpu_time] DESC

五、查询CPU占用高的语句

 
SQL 代码   复制
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句SELECT TOP 10
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 total_worker_time/execution_count AS avg_cpu_cost, plan_handle,
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 execution_count,
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 (SELECT SUBSTRING(text, statement_start_offset/2 + 1,
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 (CASE WHEN statement_end_offset = -1
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 THEN LEN(CONVERT(nvarchar(max), text)) * 2
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 ELSE statement_end_offset
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 END - statement_start_offset)/2)
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句 FROM sys.dm_exec_sql_text(sql_handle)) AS query_text
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句FROM sys.dm_exec_query_stats
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句
SQL Server中查询CPU占用高的SQL语句ORDER BY [avg_cpu_cost] DESC
SQL Server中查询CPU占用高的SQL语句
上一篇:OpenGL超级宝典visual studio 2013开发环境配置,GLTools


下一篇:sql server 任务调度与CPU