/* 
Details About Statistics
Original Author: Pinal Dave 

https://blog.sqlauthority.com/2011/06/29/sql-server-find-details-for-statistics-of-whole-database-dmv-t-sql-script/
*/

SELECT DISTINCT OBJECT_NAME(s.[object_id]) AS TableName,
                c.[name] AS ColumnName,
                s.[name] AS StatName,
                [s].[auto_created],
                [s].[user_created],
                [s].[no_recompute],
                s.[object_id],
                s.[stats_id],
                [sc].[stats_column_id],
                sc.[column_id],
                STATS_DATE(s.[object_id], s.[stats_id]) AS LastUpdated
  FROM sys.stats s
  JOIN sys.stats_columns sc
    ON sc.[object_id]  = s.[object_id]
   AND sc.[stats_id]   = s.[stats_id]
  JOIN sys.columns c
    ON c.[object_id]   = sc.[object_id]
   AND c.[column_id]   = sc.[column_id]
  JOIN sys.partitions par
    ON par.[object_id] = s.[object_id]
  JOIN sys.objects obj
    ON par.[object_id] = obj.[object_id]
 WHERE OBJECTPROPERTY(s.object_id, 'IsUserTable') = 1
 AND OBJECT_NAME(s.[object_id]) = 'PSA_T1_DOCUMENT_LINE'
   AND (   [s].[auto_created]                     = 1
      OR   [s].[user_created]                     = 1);


RETURN

SELECT OBJECT_NAME(s.object_id) AS object_name,
    COL_NAME(sc.object_id, sc.column_id) AS column_name,
    s.name AS statistics_name
FROM sys.stats AS s
INNER JOIN sys.stats_columns AS sc
    ON s.stats_id = sc.stats_id AND s.object_id = sc.object_id
WHERE s.name like '_WA%'
ORDER BY [object_name];