我想找出数据库中哪些表使用最多(我的意思是读/写字节/表大小比)或IO /表大小比.决定哪些表放在较快的光盘上,哪些表放在较慢的光盘上.有任何想法吗?
我尝试使用dm_db_index_usage_stats
但是如何找出单个搜索/扫描下有多少IO?
先感谢您.
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)
Run Code Online (Sandbox Code Playgroud)
顺便说一句,要检查的是免费的Red-Gate的脚本管理器,它有一系列用于诊断信息的SQL脚本(不,我不为它们工作).