Querying table index stats not working

Jani Hämäläinen 105 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.
5,373 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,623 questions
Developer technologies Transact-SQL
SQL Server Other
{count} votes

Accepted answer
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.