How to find out SQL Server table's read/write statistics?

后端 未结 4 1041
轻奢々
轻奢々 2020-12-24 14:42

Is there a way to find a statistics on table read and write count on SQL Server 2005/2008?

I am specifically looking for DMVs/DMFs without usin

4条回答
  •  佛祖请我去吃肉
    2020-12-24 15:09

    Following query can be used to find number of read and writes on all tables in a database. This query result can be exported to CSV file and then using excel formulas you can easily calculate read/write ratio. Very useful while planning indexes on a table

    DECLARE @dbid int
    SELECT @dbid = db_id('database_name')
    
    SELECT TableName = object_name(s.object_id),
           Reads = SUM(user_seeks + user_scans + user_lookups), Writes =  SUM(user_updates)
    FROM sys.dm_db_index_usage_stats AS s
    INNER JOIN sys.indexes AS i
    ON s.object_id = i.object_id
    AND i.index_id = s.index_id
    WHERE objectproperty(s.object_id,'IsUserTable') = 1
    AND s.database_id = @dbid
    GROUP BY object_name(s.object_id)
    ORDER BY writes DESC
    

提交回复
热议问题