Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 991
dance2die Avatar asked Oct 15 '09 23:10

dance2die


People also ask

How do I find statistics in SQL Server?

SSMS to view SQL Server StatisticsConnect to a SQL Server instance in SSMS and expand the particular database. Expand the object ( for example, HumanResources. Employee), and we can view all available statistics under the STATISTICS tab. We can get details about any particular statistics as well.

How do I check for SQL Server update statistics?

To update statistics manually we can use the UPDATE STATISTICS command or the built-in stored procedure sp_updatestats. sp_updatestats will update the statistics for every user defined table in the database it is run against.

Where are statistics stored in SQL Server?

As you might have figured out from the above T-SQL example, SQL Server statistics are stored in the sys. stats system catalog view, which contains a row for each statistics object for SQL Server tables, indexes and indexed views in the database.


1 Answers

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
like image 101
TechCoze Avatar answered Oct 19 '22 22:10

TechCoze