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

dance2die picture dance2die · Oct 16, 2009 · Viewed 39.2k times · Source

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 using triggers or audits.

The goal here is to find out appropriate fill factor for indexes - got an idea from this article (Fill Factor Defined).


[UPDATE] There is a follow up question on ServerFault
How to determine Read/Write intensive table from DMV/DMF statistics

Answer

TechCoze picture TechCoze · Feb 22, 2012

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