<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www2.sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Kalen Delaney : DMVs</title><link>http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/DMVs/default.aspx</link><description>Tags: DMVs</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Geek City: More statistics info available!</title><link>http://www2.sqlblog.com/blogs/kalen_delaney/archive/2013/04/09/more-statistics-info.aspx</link><pubDate>Wed, 10 Apr 2013 01:39:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:48605</guid><dc:creator>Kalen Delaney</dc:creator><slash:comments>0</slash:comments><comments>http://www2.sqlblog.com/blogs/kalen_delaney/comments/48605.aspx</comments><wfw:commentRss>http://www2.sqlblog.com/blogs/kalen_delaney/commentrss.aspx?PostID=48605</wfw:commentRss><description>I just started using a new DMV (one that’s actually an ‘F’ not a ‘V’, as in Function) that gives us more info about distribution statistics. It returns info about the last statistics update date (which is also available with a function STATS_DATE())....(&lt;a href="http://www2.sqlblog.com/blogs/kalen_delaney/archive/2013/04/09/more-statistics-info.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://www2.sqlblog.com/aggbug.aspx?PostID=48605" width="1" height="1"&gt;</description><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/DMVs/default.aspx">DMVs</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/statistics/default.aspx">statistics</category></item><item><title>Geek City: Space Used By Worktables</title><link>http://www2.sqlblog.com/blogs/kalen_delaney/archive/2008/11/26/space-used-by-worktables.aspx</link><pubDate>Wed, 26 Nov 2008 17:08:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:10129</guid><dc:creator>Kalen Delaney</dc:creator><slash:comments>6</slash:comments><comments>http://www2.sqlblog.com/blogs/kalen_delaney/comments/10129.aspx</comments><wfw:commentRss>http://www2.sqlblog.com/blogs/kalen_delaney/commentrss.aspx?PostID=10129</wfw:commentRss><description>&lt;P&gt;Today, a reader asked me the following:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;"How can I find the amount of space occupied by a worktable?. Using SET STATISTICS IO ON, I can only see the number of reads using the worktable, not the amount of space taken."&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What is a worktable? 
&lt;P&gt;I always like to think of it as a temp table that SQL Server builds without being asked. While preparing to write this post, I decided to see if I could find a formal definition. Books Online for SQL Server 2005 gives the following definition in the topic "Worktables": 
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Worktables are generated for certain GROUP BY, ORDER BY, or UNION queries. For example, if an ORDER BY clause references columns that are not covered by any indexes, the relational engine may need to generate a worktable to sort the result set into the order requested. Worktables are also sometimes used as spools that temporarily hold the result of executing a part of a query plan.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then I went to one of my favorite whitepapers, &lt;A href="http://www.microsoft.com/technet/prodtechnol/sql/2005/workingwithtempdb.mspx" target=_blank&gt;"Working with tempdb in SQL Server 2005",&lt;/A&gt;&amp;nbsp; which I strongly suggest you take a look at, if you're at all interested in keeping track of your &lt;EM&gt;tempdb&lt;/EM&gt; database.&amp;nbsp; It had a slightly different definition:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Work tables are temporary objects and are used to store results for query spool, LOB variables, and cursors.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So there is some overlap, in that both definitions mention spools. 
&lt;P&gt;Prior to SQL Server 2005, the best we could do was watch the STATISTICS IO value, and look at the page reads for any worktables created in the query, but, as my reader mentions, those values show us the number of reads, not the total size of the tables . There were/are some Performance Monitor counters that let us see how many worktables were created, but they don't mention the size. 
&lt;P&gt;SQL Server 2005 provides us a couple of DMVs that can be helpful. 
&lt;P&gt;The first, &lt;EM&gt;sys.dm_db_file_space_usage&lt;/EM&gt;, has a name that seems like it will provide information about all your databases, but it turns out it just provides information for tempdb. I usually use this view to keep track of the version store space, but it also tells me how much space is used for user objects (explicit temp tables) and internal objects (which include worktables). 
&lt;P&gt;The second, &lt;EM&gt;sys.dm_db_session_space_usage&lt;/EM&gt;, reports information for each session, so you can filter it by the session_id you are interested in . For you current session, you can look at @@spid: 
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;SELECT * FROM sys.dm_db_session_space_usage&lt;BR&gt;WHERE session_id = @@spid;&lt;/FONT&gt; 
&lt;P&gt;During testing, the above can be useful, to look at the values before you run a test, and then look at the values afterwards, and compute the difference. This still doesn't give you the exact size of your worktables, but it can give you some ideas. In fact, the above mentioned whitepaper states that there is no way to get the number of pages used by any specific internal object in tempdb. 
&lt;P&gt;The whitepaper gives you code to create a table called &lt;EM&gt;tempdb_space_usage&lt;/EM&gt; and a stored procedure called &lt;EM&gt;sp_sampleTempDbSpaceUsage&lt;/EM&gt; to populate the table. It also provides half a dozen queries to examine the data collected. 
&lt;P&gt;You should be able to get a much better handle on what is using your tempdb space by following the guidelines in the whitepaper and running some of the provided queries. 
&lt;P&gt;Have fun! 
&lt;P&gt;&lt;FONT color=#ff00ff size=4&gt;~Kalen&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www2.sqlblog.com/aggbug.aspx?PostID=10129" width="1" height="1"&gt;</description><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/DMVs/default.aspx">DMVs</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/internals/default.aspx">internals</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/storage/default.aspx">storage</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/temp+tables/default.aspx">temp tables</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/tempdb/default.aspx">tempdb</category></item><item><title>Geek City: Why I still need Sysprocesses</title><link>http://www2.sqlblog.com/blogs/kalen_delaney/archive/2008/06/29/why-i-still-need-sysprocesses.aspx</link><pubDate>Mon, 30 Jun 2008 03:48:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:7566</guid><dc:creator>Kalen Delaney</dc:creator><slash:comments>20</slash:comments><comments>http://www2.sqlblog.com/blogs/kalen_delaney/comments/7566.aspx</comments><wfw:commentRss>http://www2.sqlblog.com/blogs/kalen_delaney/commentrss.aspx?PostID=7566</wfw:commentRss><description>&lt;P&gt;I've said many times that my favorite new feature in SQL Server 2005 is the new metadata, in particular the new Dynamic Management Objects. When I have to do troubleshooting on a SQL Server 2000 system, it is worse than painful, not to have my favorite tools like &lt;EM&gt;sys.dm_tran_locks&lt;/EM&gt;, &lt;EM&gt;sys.dm_exec_cached_plans&lt;/EM&gt; and&lt;BR&gt;&lt;EM&gt;sys.dm_exec_query_plan&lt;/EM&gt;. By now, on the eve of the release of the version AFTER SQL Server 2005, my transition to the new metadata is almost complete. &lt;/P&gt;
&lt;P&gt;With one notable exception...&lt;/P&gt;
&lt;P&gt;I have always used &lt;EM&gt;sysprocesses&lt;/EM&gt; constantly for troubleshooting information. Although most of the useful information that allows me to see what sessions are using lots of memory, or performing lots of I/O, can found in &lt;EM&gt;sys.dm_exec_sessions&lt;/EM&gt;, there is one piece of information that isn't there. &lt;EM&gt;Sysprocesses&lt;/EM&gt; contains a columns called &lt;EM&gt;open_tran&lt;/EM&gt; which reflects the transaction&amp;nbsp; nesting of each session. If a session issues four BEGIN TRAN commands, with no COMMITs or ROLLBACKs, their session will have an &lt;EM&gt;open_tran&lt;/EM&gt; value in &lt;EM&gt;sysprocesses&lt;/EM&gt; of 4. Any &lt;EM&gt;open_tran&lt;/EM&gt; value greater than 0 might mean that a transaction is holding locks and blocking other processes, or it might be keeping the transaction log from being cleared. If you ever notice &lt;EM&gt;open_tran&lt;/EM&gt; values in higher than 2 or 3, it's a pretty good indication that a developer doesn't know much about SQL Server transaction management. I use this value all the time, and once had to troubleshoot a system where dozens of connections had open_tran values in the 20s and 30s! (For more details about nesting transactions, see my &lt;A href="http://sqlblog.com/blogs/kalen_delaney/archive/2007/08/13/did-you-know-nesting-transactions.aspx" target=_blank&gt;earlier post&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;So imagine my surprise when I discovered that the &lt;EM&gt;sys.dm_exec_sessions&lt;/EM&gt; view, which is supposed to 'replace' &lt;EM&gt;sysprocesses&lt;/EM&gt; in SQL Server 2005, has no column to provide this information!&amp;nbsp; Another view, &lt;EM&gt;sys.dm_exec_requests&lt;/EM&gt;, has a column called &lt;EM&gt;open_transaction_count&lt;/EM&gt;, which you might think would be the same thing. And it actually is the same information, but the &lt;EM&gt;sys.dm_exec_requests&lt;/EM&gt; view only returns rows for sessions that are currently active, i.e. currently running a query. The need for examining the &lt;EM&gt;open_tran&lt;/EM&gt; value is greatest when looking at those sessions that aren't doing anything, but are just sitting there with an open transaction. Those are the processes that you need to troubleshoot. I had felt that the omission of &lt;EM&gt;open_tran&lt;/EM&gt; (or &lt;EM&gt;open_transaction_count&lt;/EM&gt;) from &lt;EM&gt;sys.dm_exec_sessions&lt;/EM&gt; was just an oversight, and it would be 'fixed' in the next release. But it appears I am to be disappointed. I just checked &lt;EM&gt;sys.dm_exec_sessions&lt;/EM&gt; in RC0, and there is still no &lt;EM&gt;open_transaction_count&lt;/EM&gt; column.&lt;/P&gt;
&lt;P&gt;So long live &lt;EM&gt;sysprocesses&lt;/EM&gt;!&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff00ff size=4&gt;~Kalen&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www2.sqlblog.com/aggbug.aspx?PostID=7566" width="1" height="1"&gt;</description><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/DMVs/default.aspx">DMVs</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/metadata/default.aspx">metadata</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/Transactions/default.aspx">Transactions</category></item><item><title>Did You Know? Fragmentation, revisited....</title><link>http://www2.sqlblog.com/blogs/kalen_delaney/archive/2008/02/28/fragmentation-revisited.aspx</link><pubDate>Fri, 29 Feb 2008 01:00:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:5345</guid><dc:creator>Kalen Delaney</dc:creator><slash:comments>7</slash:comments><comments>http://www2.sqlblog.com/blogs/kalen_delaney/comments/5345.aspx</comments><wfw:commentRss>http://www2.sqlblog.com/blogs/kalen_delaney/commentrss.aspx?PostID=5345</wfw:commentRss><description>&lt;P&gt;&lt;FONT size=1&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A couple of questions arrived regarding my earlier post about &lt;A href="http://sqlblog.com/blogs/kalen_delaney/archive/2008/01/17/fragmentation-on-the-system-tables.aspx" target=_blank&gt;fragmentation on the system tables&lt;/A&gt;, and since the questions really don't have anything to do with system tables, I felt they deserved a new post.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;1) Using the DETAILED option includes the non-zero index-levels as well (non-leaf pages).&amp;nbsp; According to many source, this should also be actioned, seeing that this indicates "logical" fragmentation (meaning that the leaf pages are not in the order of the non-leaf keys any more).&amp;nbsp; I cannot find anything conclusive on this.&amp;nbsp; Where as the index level=0 occurrences, indicates extent fragmentation.&amp;nbsp; We are using this dmv, to check fragmentation-levels first, and based on that, do the necessary re-index/reorg.&amp;nbsp; Currently we are using the LIMITED option (which only shows leaf-level), but we seem to be missing indexes that needs to be re-indexed/re-orged.&lt;/STRONG&gt;&lt;/EM&gt; 
&lt;P&gt;There are two&amp;nbsp; misunderstandings reflected in this question. Although there are several types of fragmentation, the value in the avg_fragmentation_in_percent represents only logical fragmentation, in any level of any index. Yes, there can be logical fragmentation in the upper levels, which may need to be addressed in some very large tables. Extent fragmentation is only reported for heaps, and once you have a clustered index, the table itself is just the leaf level of the index.&amp;nbsp; So basically, there is no difference between the meaning of the avg_fragmentation_in_percent value no matter what level you are at. However, fragmentation is really only an issue if there are LOTS of pages. I usually say that if there are less than 100 pages, you should never worry about fragmentation. However, this this whitepaper suggests that a better cutoff would actually be 1000 pages: 
&lt;P&gt;&lt;A href="http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx"&gt;http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx&lt;/A&gt; 
&lt;P&gt;It would need to be a very big table to have upper levels of indexes with more than 1000 pages, and the sys.dm_db_index_physical_stats view does show you the number of pages at each level. 
&lt;P&gt;The second misunderstanding involves what LIMITED means. LIMITED does not ONLY show leaf level, in fact, just the opposite. LIMITED does not evaluate pages at the leaf level at all. It can still determine the logical fragmentation because of the pointers in the upper levels, but LIMITED will return no values that require actually examining the leaf level rows. This includes values like min, max and avg record size, ghost and forwarded records counts, and the value for avg_page_space_used_in_percent. If you just want to see logical fragmentation to know if defrag or reorg might help, LIMITED should be fine. 
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;2)&amp;nbsp;&amp;nbsp; Secondly, the stats that this function return, does not seem to be reliable.&amp;nbsp; I ran the function prior to an ALTER…. REBUILD, and then again thereafter.&amp;nbsp; There were hardly any differences in the stats.&amp;nbsp; Is it now a case of the stats being unreliable, or the REBUILD not being effective?&lt;/STRONG&gt;&lt;/EM&gt; 
&lt;P&gt;REBUILD doesn't seem to make a difference in the avg_fragmentation_in_percent value is when there are too few pages in the table. &lt;/P&gt;&lt;img src="http://www2.sqlblog.com/aggbug.aspx?PostID=5345" width="1" height="1"&gt;</description><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/DMVs/default.aspx">DMVs</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/fragmentation/default.aspx">fragmentation</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/indexes/default.aspx">indexes</category></item><item><title>Geek City: Fragmentation on the System Tables</title><link>http://www2.sqlblog.com/blogs/kalen_delaney/archive/2008/01/17/fragmentation-on-the-system-tables.aspx</link><pubDate>Fri, 18 Jan 2008 01:05:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:4576</guid><dc:creator>Kalen Delaney</dc:creator><slash:comments>4</slash:comments><comments>http://www2.sqlblog.com/blogs/kalen_delaney/comments/4576.aspx</comments><wfw:commentRss>http://www2.sqlblog.com/blogs/kalen_delaney/commentrss.aspx?PostID=4576</wfw:commentRss><description>&lt;P&gt;It's my first post of the new year. I hope it's starting out well for all of you! New year, but sometimes the same old questions. I got another email asking about defragging the system tables. It seems to be in the Hit Parade of FAQs. &lt;/P&gt;
&lt;P&gt;First of all, WHY do you think you would need to defrag a system table? Fragmentation is only a problem when you are performing an in-order scan on a table of more than 100 pages or so, and how often do you do that to a system table that is that big? Rarely, I would assume, but let me know if you have seen an actual need for defragging a system table.&lt;/P&gt;
&lt;P&gt;In SQL Server 2000, you can actually use a system table as a parameter to DBCC SHOWCONTIG to see the fragmentation values. One of my readers reported that he tried running a DBCC INDEXDEFRAG on SQL 2000 system tables and while sometimes it worked, sometimes it corrupted the table! It doesn't sound worth it to me. &lt;/P&gt;
&lt;P&gt;And now, with SQL Server 2005 there is no way to see the fragmentation on the system tables. What about using the new Dynamic Management Object sys.dm_db_index_physical_stats? It requires an object_id as a parameter, and if you select from the metadata view sys.all_objects you can see the object_id for the real system tables, even if you're not using the DAC. Try this:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=#004080&gt;select * from sys.all_objects&lt;BR&gt;where type = 'S'&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You should see all the system tables in your current database, and their object IDs. So you could try passing the id to the management view. Here I'll try it for &lt;EM&gt;syshobts&lt;/EM&gt;, which has an ID of 15:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT color=#000080&gt;&lt;FONT face="Courier New"&gt;select * from &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT face="Courier New"&gt;sys.dm_db_index_physical_stats(1, 15, null, null, 'detailed')&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No results are returned. If I replace the 15 with null, to indicate I want all objects, I do not see any objects with IDs less than 100, which means there are no system objects reported.&lt;/P&gt;
&lt;P&gt;I did notice one interesting behavior while playing around with this concept. If I use the old DBCC SHOWCONTIG and try to get a report for a system table, this command gives me an error:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="courier new" color=#004080&gt;dbcc showcontig ('syshobts')&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new" color=#ff0000&gt;Msg 2501, Level 16, State 45, Line 1&lt;BR&gt;Cannot find a table or object with the name "syshobts". Check the system catalog.&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;However, if I qualify the table name with the schema name, something different happens.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="courier new" color=#004080&gt;dbcc showcontig ('sys.syshobts')&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This time, I don't get an error. I don't get a fragmentation report, but I don't get an error. I just get the message that DBCC execution completed. So it's obvious that there is a difference here. If I then intentionally misspell the object name&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="courier new" color=#004080&gt;dbcc showcontig ('sys.syshobbits')&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;now I get the error that SQL Server cannot find the object. So it seems that in SQL Server 2005, DBCC SHOWCONTIG is deliberately filtering out the real system tables, and it was by design to not return fragmentation information. So even if you could run defrag on your system tables, you could never know what impact you had!&lt;/P&gt;
&lt;P&gt;I think there's better ways to spend our time.&lt;/P&gt;
&lt;P&gt;Have fun!&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff00ff&gt;~Kalen&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www2.sqlblog.com/aggbug.aspx?PostID=4576" width="1" height="1"&gt;</description><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/DMVs/default.aspx">DMVs</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/fragmentation/default.aspx">fragmentation</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/internals/default.aspx">internals</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/metadata/default.aspx">metadata</category></item><item><title>Geek City: HyperThreaded or Not?</title><link>http://www2.sqlblog.com/blogs/kalen_delaney/archive/2007/12/08/hyperthreaded-or-not.aspx</link><pubDate>Sat, 08 Dec 2007 23:56:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:3786</guid><dc:creator>Kalen Delaney</dc:creator><slash:comments>8</slash:comments><comments>http://www2.sqlblog.com/blogs/kalen_delaney/comments/3786.aspx</comments><wfw:commentRss>http://www2.sqlblog.com/blogs/kalen_delaney/commentrss.aspx?PostID=3786</wfw:commentRss><description>&lt;P&gt;In almost all my classes, and every time I do any performance consulting, I get the question "How can I determine if our SQL Server is hyperthreaded?"&lt;/P&gt;
&lt;P&gt;I was delighted when I found the DMV sys.dm_sys_info, which has a column called hyperthread_ratio. But soon after, I read &lt;A href="http://blogs.msdn.com/buckwoody/archive/2007/08/13/script-of-the-day-find-the-cores-on-a-system.aspx"&gt;a blog post&lt;/A&gt; from one of my favorite SQL Server bloggers, Buck Woody who indicated that the following query gives you the number of cores, but doesn't specifically tell you if the hyperthreading is enabled. &lt;BR&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;SELECT cpu_count/hyperthread_ratio AS &lt;STRONG&gt;sockets&lt;/STRONG&gt;&lt;BR&gt;FROM sys.dm_os_sys_info&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Although he said this gives you the number of cores, that is not correct either, because one socket can contain a &lt;A title="Wikipedia: multi-core" href="http://en.wikipedia.org/wiki/Multi-core_(computing)"&gt;multi-core&lt;/A&gt; CPU. A computer with a single socket containing a dual-core CPU and no hyperthreading will have a cpu_count value of 2, and a hyperthread_ratio of 2, and a computer with a single socket single core CPU with hyperthreading will also have the same hyperthread_ratio. In both cases, dividing hyperthread_ratio by cpu_count will give 1, the number of sockets. If we have a single socket machine with a dual-core CPU and hyperthreading, cpu_count will be 4 and hyperthread_ratio will also be four, so the ratio again will be one. So the values for single socket possibilities are summarized here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE class="" cellSpacing=0 cellPadding=2&gt;

&lt;TR&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;&lt;B&gt;Number of Sockets&lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;&lt;B&gt;Number of Cores&lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;STRONG&gt;Hyperthreaded?&lt;/STRONG&gt; &lt;/TD&gt;
&lt;TD class=""&gt;&lt;B&gt;sys.dm_os_info.&lt;BR&gt;cpu_count&lt;/B&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;&lt;B&gt;sys.dm_os_info.&lt;BR&gt;hyperthread_ratio&lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;&lt;B&gt;cpu_count / hyperthread_ratio&lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;1&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;2&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;NO&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;2&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;2&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;1&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;1&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;YES&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;2&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;2&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;1&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;2&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;YES&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;4&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;4&lt;/P&gt;&lt;/TD&gt;
&lt;TD class=""&gt;
&lt;P align=center&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So even though Buck said his formula would show you the number of cores, the query itself tells the truth and the output column is named 'sockets'. The ratio of cpu_count to hyperthread_ratio shows the number of sockets, not the number of cores, and there is no way to tell the difference between hyperthreading and dual-core. &lt;/P&gt;
&lt;P&gt;I have heard that this relationship and the values returned can be different on Vista or later operating systems, but since I am not running Vista, I have no way to test it out for myself. But maybe you can. &lt;/P&gt;
&lt;P&gt;:-)&lt;/P&gt;
&lt;P&gt;Have fun!&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff00ff&gt;~Kalen&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www2.sqlblog.com/aggbug.aspx?PostID=3786" width="1" height="1"&gt;</description><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/CPUs/default.aspx">CPUs</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/DMVs/default.aspx">DMVs</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/Hyperthreading/default.aspx">Hyperthreading</category></item><item><title>Did You Know? The Best SQL Server 2005 Feature</title><link>http://www2.sqlblog.com/blogs/kalen_delaney/archive/2007/12/04/the-best-sql-server-2005-feature.aspx</link><pubDate>Wed, 05 Dec 2007 05:44:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:3691</guid><dc:creator>Kalen Delaney</dc:creator><slash:comments>9</slash:comments><comments>http://www2.sqlblog.com/blogs/kalen_delaney/comments/3691.aspx</comments><wfw:commentRss>http://www2.sqlblog.com/blogs/kalen_delaney/commentrss.aspx?PostID=3691</wfw:commentRss><description>&lt;P&gt;This post really should have a topic of "Pet Peeve" but I really didn't want to sound quite so negative. &lt;/P&gt;
&lt;P&gt;It seems like almost every time I see a clever solution in a newsgroup response, or in a blog post, about how to extract some very useful troubleshooting information using the Dynamic Management Views, someone will ask for an equivalent query in SQL Server 2000.&amp;nbsp; It just happened again as I was doing a google search and came across a post by Kevin Kline right here on sqlblog about using the new metadata to get information about &lt;A href="http://sqlblog.com/blogs/kevin_kline/archive/2007/10/23/tempdb-space-usage.aspx"&gt;space usage in tempdb&lt;/A&gt;. It was actually referring to a query developed by Aaron Bertrand, who also posts here. Someone asked if there was a way to do the same thing in SQL 2005, but we assume they meant SQL 2000. Our own Adam Machanic responded that the CROSS APPLY operator was not available in SQL 2000, but that is the least of our worries. The query refers to seven different Dynamic Management Objects (6 views and a function), most of which have no equivalent in SQL Server 2000. &lt;/P&gt;
&lt;P&gt;It just seems that some people seem to think that anything we can do in one version should be doable in a previous version. If that were true, why would you upgrade? Do you only upgrade for performance benefits? I don't think so. &lt;/P&gt;
&lt;P&gt;In my opinion, the BEST SQL Server 2005 feature is the new system metadata. It is absolutely worth the price of admission. There are so many things that you couldn't even begin to find out about with the metadata from SQL 2000, and the only way to get that level of internal detail is to UPGRADE!&lt;/P&gt;
&lt;P&gt;If you're running SQL 2005, the Dynamic Management Objects can provide hours and hours of fun and exciting explorations!&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff00ff&gt;~Kalen&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www2.sqlblog.com/aggbug.aspx?PostID=3691" width="1" height="1"&gt;</description><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/DMVs/default.aspx">DMVs</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/Upgrade/default.aspx">Upgrade</category></item></channel></rss>