Created
April 5, 2023 19:20
-
-
Save ghotz/1b01375c27d8713d3a38bdb4400e7782 to your computer and use it in GitHub Desktop.
Search for statistics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Search statistics with leading column name | |
SELECT | |
OBJECT_SCHEMA_NAME(C2.[object_id]) AS [schema_name] | |
, OBJECT_NAME(C2.[object_id]) AS [table_name] | |
, S1.[name] AS stats_name | |
, S1.auto_created | |
, P1.* | |
FROM sys.stats AS S1 | |
JOIN sys.stats_columns AS C1 ON S1.[object_id] = C1.[object_id] AND S1.stats_id = C1.stats_id | |
JOIN sys.columns AS C2 ON C1.[object_id] = C2.[object_id] AND C1.column_id = C2.column_id | |
JOIN sys.all_objects AS O1 ON C2.[object_id] = O1.[object_id] | |
CROSS | |
APPLY sys.dm_db_stats_properties(S1.[object_id], S1.stats_id) AS P1 | |
WHERE C2.[name] LIKE 'OrderDate' | |
AND O1.[name] LIKE 'SalesOrder%' | |
AND C1.stats_column_id = 1; | |
GO | |
-- Get histogram | |
SELECT * FROM sys.dm_db_stats_histogram(1010102639, 13); | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment