Listing How Many CPU’s SQL Server Physically Sees in SQL Server
Hello everyone,
In this article, I will try to give information about listing how many CPUs SQL Server physically sees in SQL Server.
In SQL Server, in some cases, you may want to list how many CPUs SQL Server physically sees.
You can easily do this using the code below.
DECLARE @xp_msver TABLE
(
[idx] [INT] NULL,
[c_name] [VARCHAR](100) NULL,
[int_val] [FLOAT] NULL,
[c_val] [VARCHAR](128) NULL
);
INSERT INTO @xp_msver
EXEC ('[master]..[xp_msver]');;
WITH [ProcessorInfo]
AS (SELECT ([cpu_count] / [hyperthread_ratio]) AS [number_of_physical_cpus],
CASE
WHEN hyperthread_ratio = cpu_count THEN
cpu_count
ELSE
(([cpu_count] - [hyperthread_ratio]) / ([cpu_count] / [hyperthread_ratio]))
END AS [number_of_cores_per_cpu],
CASE
WHEN hyperthread_ratio = cpu_count THEN
cpu_count
ELSE
([cpu_count] / [hyperthread_ratio])
* (([cpu_count] - [hyperthread_ratio]) / ([cpu_count] / [hyperthread_ratio]))
END AS [total_number_of_cores],
[cpu_count] AS [number_of_virtual_cpus],
(
SELECT [c_val] FROM @xp_msver WHERE [c_name] = 'Platform'
) AS [cpu_category]
FROM [sys].[dm_os_sys_info])
SELECT [number_of_physical_cpus],
[number_of_cores_per_cpu],
[total_number_of_cores],
[number_of_virtual_cpus],
LTRIM(RIGHT([cpu_category], CHARINDEX('x', [cpu_category]) - 1)) AS [cpu_category]
FROM [ProcessorInfo];
Good luck to everyone in business and life.