Get the Number of CPUs on a ‘SQL Server’ Machine

Script to get the number of physical and logical CPUs (processors) on a ‘SQL Server’ Server Machine. Uses the sys.dm_os_sys_info System View.

Note: You should run the script on the Server Machine itself. If you connect to the Server using SQL Client from your local machine, this script will show you the CPUs on your machine, not the server machine.

Script Version:

-- ------------------------------------
-- From: http://mycodetrip.com
-- URL: http://mycodetrip.com/?p=78
-- Remarks: returns the number of
--    logical and physical CPUs on
--    a 'sql server' server machine
-- ------------------------------------
select cpu_count 'logical_cpus'                     -- logical cpus
, (cpu_count / hyperthread_ratio) 'physical_cpus'   -- physical cpus
from sys.dm_os_sys_info

Stored Procedure Version:

create procedure usp_GetServerCpusCount
as
-- ------------------------------------
-- From: http://mycodetrip.com
-- URL: http://mycodetrip.com/?p=78
-- Remarks: returns the number of
--    logical and physical CPUs on
--    a 'sql server' server machine
-- ------------------------------------
begin
select cpu_count 'logical_cpus'                     -- logical cpus
, (cpu_count / hyperthread_ratio) 'physical_cpus'   -- physical cpus
from sys.dm_os_sys_info
end

You get the 2nd comment!

  1. Michael B says:

    Fantastic! Thanks.

Leave a Reply