How do you list all the indexed views in SQL Server?

EBarr picture EBarr · Feb 10, 2011 · Viewed 14.2k times · Source

How can you get a list of the views in a SQL server database that have indexes (i.e. indexed views)?

I've found it's pretty easy to run an "ALTER VIEW" as I'm developing and overlook that I'm not only editing the view but also dropping an existing index. So I thought it would be nice to have a little utility query around that would list me off all the views with indexes.

Answer

Joe Stefanelli picture Joe Stefanelli · Feb 10, 2011
SELECT o.name as view_name, i.name as index_name
    FROM sysobjects o 
        INNER JOIN sysindexes i 
            ON o.id = i.id 
    WHERE o.xtype = 'V' -- View