Sql server 表使用情况统计

Sql server table usage statistics(Sql server 表使用情况统计)
本文介绍了Sql server 表使用情况统计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找出数据库中哪些表使用最频繁(我的意思是读/写字节/表大小比率)或 IO/表大小比率.决定将哪些表放在较快的磁盘上,哪些放在较慢的磁盘上.有什么想法吗?

I want to find out which tables in the database are most heavily used (I mean read/write Bytes/Table Size ratio) or IO / Table size ratio. To decide which tables to place on faster discs and which on slower ones. Any ideas?

我尝试使用 dm_db_index_usage_stats
但是如何找出单次搜索/扫描下有多少IO?

I tried make use of dm_db_index_usage_stats
But how to find out how many IO are under single seek/scan?

提前致谢.

推荐答案

Select object_schema_name(UStat.object_id) 
        + '.' + object_name(UStat.object_id) As [Object Name] 
    ,Case
        When Sum(User_Updates + User_Seeks + User_Scans + User_Lookups) = 0 Then Null
        Else Cast(Sum(User_Seeks + User_Scans + User_Lookups) As Decimal)
                    / Cast(Sum(User_Updates 
                                + User_Seeks 
                                + User_Scans
                                + User_Lookups) As Decimal(19,2))
        End As [Proportion of Reads] 
    , Case
        When Sum(User_Updates + User_Seeks + User_Scans + User_Lookups) = 0 Then Null
        Else Cast(Sum(User_Updates) As Decimal)
                / Cast(Sum(User_Updates 
                            + User_Seeks 
                            + User_Scans
                            + User_Lookups) As Decimal(19,2))
        End As [Proportion Of Writes] 
    , Sum(User_Seeks + User_Scans + User_Lookups) As [Total Read Ops] 
    , Sum(User_Updates) As [Total Write Ops]
From sys.dm_db_Index_Usage_Stats As UStat
    Join Sys.Indexes As I 
        On UStat.object_id = I.object_id
            And UStat.index_Id = I.index_Id
    Join sys.tables As T
        On T.object_id = UStat.object_id
Where I.Type_Desc In ( 'Clustered', 'Heap' )
Group By UStat.object_id
Order By object_schema_name(UStat.object_id) 
        + '.' + object_name(UStat.object_id)

顺便说一句,需要检查的是免费的 Red-Gate 脚本管理器,它有一系列用于诊断信息的 SQL 脚本(不,我不为它们工作).

Btw, something to check out is free Red-Gate's Script Manager which has a series of SQL scripts for diagnostic information (no I do not work for them).

SQL 脚本管理器

这篇关于Sql server 表使用情况统计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)