Question: How can I use Transact-SQL to determine the number of processors on my SQL Server computer programmatically?
Answer:: The following statement returns the required information:
EXEC master .. xp_msver N 'processorcount ',
N 'processortype'
However, I am keen to teach people how to fish, rather than giving them a plate of frozen fish, so I am not satisfied with the simple answer. Recently, a colleague asked me this question. I couldn't think of the appropriate command at the moment, but I know that the SQL Server Enterprise Manager displays the number of processors on the processor tab of the SQL Server properties dialog box. In addition, the enterprise manager can obtain almost all required information by running simple Transact-SQL statements on the server. In addition, you can run the SQL event probe to quickly view statements generated by the enterprise manager.
I often count the benefits of using SQL event probes and observing SQL Server running conditions. The following is another example of how to implement this suggestion. With the SQL event probe, I took only three minutes to separate the calling of the xp_msver extended stored procedure by the enterprise manager. In this case, I always think about the SQL event probe first.