Sunday 23 July 2017

Get Read/Write percentages for a SQL Server database

Using below sql script we will get the read and write percentages.
SELECT  DB_NAME(s.database_id) AS Database_Name ,
        SUM(s.user_seeks +0.000
           + s.user_scans
           + s.user_lookups
           + s.system_seeks
            + s.system_scans
           + s.system_lookups) / SUM(s.user_seeks
                                       + s.user_scans
                                       + s.user_lookups
                                       + s.user_updates
                                       + s.system_seeks
                                       + s.system_scans
                                       + s.system_lookups
                                       + s.system_updates) AS Read_Percentage ,
        SUM(s.user_updates + 0.000
           + s.system_updates) / SUM(s.user_seeks
                                        + s.user_scans
                                        + s.user_lookups
                                        + s.user_updates
                                        + s.system_seeks
                                        + s.system_scans
                                        + s.system_lookups
                                        + s.system_updates) AS Write_Percentage
FROM    sys.dm_db_index_usage_stats AS s
GROUP BY s.database_id
ORDER BY DB_NAME(s.database_id);
See the output below


No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts