Skip to content

Commit eddb207

Browse files
committed
Add SQL script Get_Statistics_Details
1 parent ea42be4 commit eddb207

File tree

2 files changed

+314
-279
lines changed

2 files changed

+314
-279
lines changed

Scripts/Get_Statistics_Details.sql

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
-- Get statistics details on SQL Server 2008 R2 and higher
2+
-- Author: Kendra Little
3+
-- "This works with SQL Server 2008 R2 SP2+ / SQL Server 2012 SP1+ / All higher versions"
4+
SELECT
5+
stat.auto_created,
6+
stat.name as stats_name,
7+
STUFF((SELECT ', ' + cols.name
8+
FROM sys.stats_columns AS statcols
9+
JOIN sys.columns AS cols ON
10+
statcols.column_id=cols.column_id
11+
AND statcols.object_id=cols.object_id
12+
WHERE statcols.stats_id = stat.stats_id and
13+
statcols.object_id=stat.object_id
14+
ORDER BY statcols.stats_column_id
15+
FOR XML PATH(''), TYPE
16+
).value('.', 'NVARCHAR(MAX)'), 1, 2, '') as stat_cols,
17+
stat.filter_definition,
18+
stat.is_temporary,
19+
stat.no_recompute,
20+
sp.last_updated,
21+
sp.modification_counter,
22+
sp.rows,
23+
sp.rows_sampled
24+
FROM sys.stats as stat
25+
CROSS APPLY sys.dm_db_stats_properties (stat.object_id, stat.stats_id) AS sp
26+
JOIN sys.objects as so on
27+
stat.object_id=so.object_id
28+
JOIN sys.schemas as sc on
29+
so.schema_id=sc.schema_id
30+
WHERE
31+
sc.name= 'Warehouse'
32+
and so.name='StockItemTransactions'
33+
ORDER BY 1, 2;
34+
GO
35+

0 commit comments

Comments
 (0)