I’m working in SQL Server 2005 up to SQL Server 2008R2. What I’m trying to do is write a query which will display a list of statistics for any given table (or potentially database!) which will show the statistics sample rates for all statistics on the table.
Now I can see this information when using a DBCC show_statistics command, however this dbcc command returns three tables in it’s resultset which prevents me from being able to capture the output into a temp table.
Independently researching the topic, I found one suggestion which was to enable xp cmd shell in order to save the results to a text file and then to import that back into SQL and parse it out with a PATINDEX, but that seems extremely clunky and involves opening a potential security vulnerability.
So what I’m looking for is either a way to capture the resultset of the first table in DBCC show_statistics (without going to vb) or for some other way to query the “Rows” and “Rows Sampled” which is displayed by DBCC.
I figured out the answer to the problem. Running the dbcc show_statistics using the with stat_header clause allows only one resultset to be displayed so it can be captured using temp tables.