2011-06-20 10 views

答えて

4

次のコードは、最後のSQLサーバーの再起動時に使用されていないテーブルとインデックスを提供します。

/*Unused tables and indexes*/  
SELECT OBJECTNAME = OBJECT_NAME(I.OBJECT_ID), INDEXNAME = I.NAME, I.INDEX_ID 
FROM SYS.INDEXES AS I 
INNER JOIN SYS.OBJECTS AS O ON I.OBJECT_ID = O.OBJECT_ID 
WHERE OBJECTPROPERTY(O.OBJECT_ID,'IsUserTable') = 1 
AND I.INDEX_ID 
NOT IN (
    SELECT S.INDEX_ID 
    FROM SYS.DM_DB_INDEX_USAGE_STATS AS S 
    WHERE S.OBJECT_ID = I.OBJECT_ID 
    AND I.INDEX_ID = S.INDEX_ID 
    AND DATABASE_ID = DB_ID(db_name()) 
) 
ORDER BY OBJECTNAME, I.INDEX_ID, INDEXNAME ASC 
関連する問題