开发者

Unused SP, Tables list from SQLSERVER 2008

I want to find SP,Tables usage history from my database as these are lot of sp's which have not u开发者_运维百科sed been for long time. Is there a script i can use to easily identify items that are not used in the database?


following code will give you unused tables and indexes FROM last SQL server restart.

/*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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜