Finding the names of all indexes on a SQL Server
I needed a way to list the indexes for an entire database, but I was running into a problem using sys.indexes that I could only see the indexes for the current database. Below is the solution that I put together to list off of the indexes in the entire database. CREATE TABLE ##allindexes(databse_id INTEGER,table_id INTEGER,index_id INTEGER,table_name VARCHAR(1024));EXECUTE Sp_msforeachdb’use [?];INSERT INTO ##AllIndexesselect DB_ID() as database_id, object_id as table_id, index_id, namefrom sys.indexeswhere name is not null’ SELECT *FROM ##allindexes;DROP TABLE ##allindexes;