How to List All ColumnStore Indexes with Table Name in SQL Server? – Interview Question of the Week #153

Question: How do I list the clustered and nonclustered columnstore indexes in a SQL Server database, together with their table names?

Answer: Columnstore indexes have become common enough that I now hear this during my database performance health checks. The question sounds like an index problem, but the useful answer is a short catalog query that keeps the schema, table, name, and type together.

Different column structures are cataloged in a single orderly stone rack

Run this in the database you want to inspect. In sys.indexes, type 5 means clustered columnstore and type 6 means nonclustered columnstore. Joining to sys.tables makes the table and schema explicit.

SELECT SCHEMA_NAME(t.schema_id) AS SchemaName,
       t.name AS TableName,
       i.name AS IndexName,
       i.type_desc AS IndexType
FROM sys.indexes AS i
JOIN sys.tables AS t
  ON t.object_id = i.object_id
WHERE i.type IN (5, 6)
  AND i.is_hypothetical = 0
ORDER BY SchemaName, TableName, IndexName;

This historical WideWorldImporters result shows two nonclustered columnstore indexes and one clustered columnstore index, with the schema, table, index name and type in four columns.

Original SSMS result listing schema, table, index name and clustered or nonclustered columnstore type
Original result: columnstore indexes listed with their parent tables.

This is a current-database inventory. If you remove the type predicate, the catalog will include the other index types too, but that is a different report. Microsoft’s sys.indexes documentation is the reference for the type values. Catalog visibility can also depend on your permissions, so an empty result is not proof that no index exists anywhere on the instance.

For more background, see my earlier articles on columnstore fundamentals, common columnstore questions, and the follow-up FAQ. I also wrote about a computed-column restriction I met at a customer site; check current feature support before carrying an old restriction into a new design.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

Clustered Index, ColumnStore Index, SQL DMV, SQL Index, SQL Scripts, SQL Server
Previous Post
How to Kill Processes Idle for X Hours? – Interview Question of the Week #152
Next Post
How to List Queries With Memory Grant and Execution Plan? – Interview Question of the Week #154

Related Posts

2 Comments. Leave new

  • The above script gives this error:

    Msg 4145, Level 15, State 1, Line 5
    An expression of non-boolean type specified in a context where a condition is expected, near ‘;’.

    Reply
  • Msg 4145, Level 15, State 1, Line 5
    An expression of non-boolean type specified in a context where a condition is expected, near ‘;’.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.