Querying table index stats not working

Jani Hämäläinen 40 Reputation points
2024-06-14T09:17:01.14+00:00

I am trying to query my tables index fragmentation in Azure Synapse studio with query:

SELECT IPS.Index_type_desc, 
      IPS.avg_fragmentation_in_percent, 
      IPS.avg_fragment_size_in_pages, 
      IPS.avg_page_space_used_in_percent, 
      IPS.record_count, 
      IPS.ghost_record_count,
      IPS.fragment_count, 
      IPS.avg_fragment_size_in_pages
   FROM sys.dm_db_index_physical_stats(DB_ID(),NULL, NULL, NULL , 'DETAILED') AS IPS


But i get error:

Parse error at line: 9, column: 40: Incorrect syntax near 'DB_ID'.


How to fix?

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,692 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,351 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,183 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,600 questions
{count} votes

Accepted answer
  1. Erland Sommarskog 107K Reputation points
    2024-06-14T21:25:10.3566667+00:00

    If you look at the topic for sys.dm_db_index_physical_stats, you will see this:

    User's image

    That is, this is DMV is not available on Synapse. I don't know how you check for fragmentation on Synapse, but it is a different engine from the regular SQL Server, so I don't even know how application the concept of fragmentation is to Synapse.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful