Find List Of Index For Tables In Sql Server



This Query will return list of indexes for particular table or all tables.

/***********************************************/
Use [AdventureWorks2012]
GO
SELECT
        A.NAME TABLE_NAME,
        B.NAME INDEX_NAME,
        D.NAME COLUMN_NAME
FROM
        SYS.TABLES A, SYS.INDEXES B,
        SYS.INDEX_COLUMNS C, SYS.COLUMNS D
WHERE
        A.OBJECT_ID = B.OBJECT_ID
        AND B.OBJECT_ID = C.OBJECT_ID
        AND B.INDEX_ID = C.INDEX_ID
        AND C.OBJECT_ID = D.OBJECT_ID
        AND C.COLUMN_ID = D.COLUMN_ID
        --AND A.NAME LIKE '%tablename%';   
/**********************************************/   



No comments:

Post a Comment