Tag Archives: CPU usage by sql service

Finding Out SQL Server CPU usage Using T-SQL Code

Hi Friends,

In many companies developers won’t be given administrator privilege in OS on their test or development machines. When they execute a query and consider its consuming high CPU usage, since they won’t have admin privilege they are not able to confirm that the CPU is consumed by sqlservice or not. I’ve written a T-SQL Code to check the CPU usage consumed by Sqlservice.
Check out the below script.

Code:

DECLARE @CPU_BUSY int, @IDLE int
SELECT @CPU_BUSY = @@CPU_BUSY, @IDLE = @@IDLE WAITFOR DELAY ’000:00:01′
SELECT (@@CPU_BUSY – @CPU_BUSY)/((@@IDLE – @IDLE + @@CPU_BUSY – @CPU_BUSY) *1.00) *100 AS ‘CPU Utilization by sqlsrvr.exe’

Output:

CPU Utilization by sqlsrvr.exe
—————————————
0.850000000000000

Hope this small script will help you to check out sqlservice usage via T-SQL Statement!

VN:F [1.9.13_1145]
Rating: 3.3/5 (4 votes cast)
VN:F [1.9.13_1145]
Rating: +1 (from 5 votes)