Query to check Statistics of tables in an Azure SQL Server database

Posted by

To include the schema in the query to check statistics on a table in Azure SQL Server, you can modify the query as follows:

SELECT 
    SCHEMA_NAME(o.schema_id) AS SchemaName,
    OBJECT_NAME(s.object_id) AS TableName,
    s.name AS StatisticName,
    STATS_DATE(s.object_id, s.stats_id) AS LastUpdated,
    s.auto_created,
    s.user_created,
    s.no_recompute,
    sp.last_updated AS SampleLastUpdated,
    sp.rows AS Rows,
    sp.modification_counter AS ModificationCounter
FROM 
    sys.stats AS s
JOIN 
    sys.objects AS o ON s.object_id = o.object_id
OUTER APPLY 
    sys.dm_db_stats_properties(s.object_id, s.stats_id) AS sp
WHERE 
    o.type = 'U' -- User-defined table
    AND SCHEMA_NAME(o.schema_id) = 'YourSchemaName' -- Replace 'YourSchemaName' with the name of your schema
    AND OBJECT_NAME(s.object_id) = 'YourTableName' -- Replace 'YourTableName' with the name of your table
ORDER BY 
    SCHEMA_NAME(o.schema_id), OBJECT_NAME(s.object_id), s.name;

The columns in the query provide information about the statistics of tables in an Azure SQL Server database. Here’s what each column represents:

  1. SchemaName: The name of the schema to which the table belongs.
  2. TableName: The name of the table.
  3. StatisticName: The name of the statistics object.
  4. LastUpdated: The date and time when the statistics were last updated.
  5. auto_created: Indicates whether the statistics were automatically created by SQL Server.
  6. user_created: Indicates whether the statistics were manually created by a user.
  7. no_recompute: Indicates whether statistics recomputation is disabled.
  8. SampleLastUpdated: The date and time when the sample statistics were last updated.
  9. Rows: The number of rows in the table.
  10. ModificationCounter: Indicates the number of modifications made to the table since the statistics were last updated.
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x