How to find statistics on specific table or column in SQL Server


To find stats on specific column on table you can run below query, I case you want to find statistics on database just comment where clause


SELECT s.name AS statistics_name 
      ,c.name AS column_name 
      ,sc.stats_column_id
         , Object_name(sc.object_id)
FROM sys.stats AS
INNER JOIN sys.stats_columns AS sc  
    ON s.object_id = sc.object_id AND s.stats_id = sc.stats_id 
INNER JOIN sys.columns AS c  
    ON sc.object_id = c.object_id AND c.column_id = sc.column_id 
WHERE s.object_id = OBJECT_ID('Person.BusinessEntityAddress')
order by column_name


Below is statistics on Adventureworks database




No comments:

Post a Comment