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

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.

Related Posts

Azure SQL Database – Hyperscale tier, the Standard-series (Gen5) and Premium-series

In Azure SQL Database – Hyperscale tier, the Standard-series (Gen5) and Premium-series hardware options differ in CPU architecture, memory, storage throughput, and performance characteristics. Here’s a clear…

Read More

Azure Log Analytics fields for Azure SQL Server/Database

Here’s a detailed explanation of the Azure Log Analytics fields for SQLSecurityAuditEvents from an Azure SQL Server (e.g., server-level audit logs): Log Analytics fields for SQLSecurityAuditEvents from…

Read More

High Availability (HA) replica in Azure SQL Database

What is a High Availability (HA) Replica? Key Features: How Data is Synced Across Replicas: Why Use HA Replicas? Simple Analogy: Think of a high-availability replica like…

Read More

Top Interview Questions on Query Hints in Azure SQL Database for Performance Optimization

Here are some interview questions related to query hints in Azure SQL Database, along with sample answers: 1. What are query hints in SQL Server or Azure…

Read More

Azure SQL Database: Scenario-Based Interview Questions for Query and System Performance Tuning

Here are scenario-based interview questions related to Azure SQL Database query tuning and system performance tuning, along with guidance on how to answer: 1. Scenario: High CPU…

Read More

Primary key constraint with a Clustered index and a regular Clustered index in Azure SQL Database

The primary key constraint with a clustered index and a regular clustered index are similar in how they physically organize data in a table, but they have…

Read More
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x