Identifying Unused Objects In Microsoft SQL Server 2005

前端 未结 1 2027
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-23 22:48

It\'s a trivial task to find out if an object is referenced by something else or not. What I\'d like to do is identify whether or not it\'s actually being used

相关标签:
1条回答
  • 2020-12-23 23:13

    With SQL Server 2005, you can use the dynamic management view sys.dm_db_index_usage_stats. The name says "index" but that's a little misleading - every table has an entry in here, even if it doesn't have any indexes. Here's a useful query from SQL Magazine:

    SELECT 
      t.name AS 'Table', 
      SUM(i.user_seeks + i.user_scans + i.user_lookups) 
        AS 'Total accesses',
      SUM(i.user_seeks) AS 'Seeks',
      SUM(i.user_scans) AS 'Scans',
      SUM(i.user_lookups) AS 'Lookups'
    FROM 
      sys.dm_db_index_usage_stats i RIGHT OUTER JOIN 
        sys.tables t ON (t.object_id = i.object_id)
    GROUP BY 
      i.object_id, 
      t.name
    ORDER BY [Total accesses] DESC
    

    Here's the original article:

    http://www.sqlmag.com/Article/ArticleID/53878/sql_server_53878.html

    Keep in mind that these usage statistics reset when SQL Server restarts.

    0 讨论(0)
提交回复
热议问题