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.

108 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!