Apr 23, 2013

Sql script to get the CPU idle time in sql server


Sql script to get the CPU idle time in sql server since last time sql server had started.

SELECT @@IDLE AS [Idle Time]

Sample Output:

Idle Time
12000


To get in second:

SELECT @@IDLE * CAST(@@TIMETICKS AS FLOAT) / 1000000 AS [Idle Time(Second)]

To get the CPU idle time during the execution of some sql queries:

DECLARE @IdleTime AS INT
SET  @IdleTime = @@IDLE

/*
    Sql statements
*/

SELECT @@IDLE -  @IdleTime AS [Idle Time]

No comments:

Post a Comment