2017-06-06 93 views
0

我們如何看到sql server 2012和更高級別中最刪除和最新的表。最新更新和刪除的表?

我們如何看到使io最多的表?

這些統計數據是否保留在Sql Server中?

+0

對於第一近似,該數據包含在['SYS。 dm_db_index_usage_stats'](https://docs.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-db-index-usage-stats-transact-sql)。不過,這只是自上次啓動以來纔有效。 –

+0

我寫這樣的:選擇OBJECT_NAME(sys.dm_db_index_usage_stats.object_id)作爲李善雄,sys.indexes.name, user_seeks,user_scans,user_lookups,從sys.dm_db_index_usage_stats上sys.dm_db_index_usage_stats.object_id = SYS內加入SYS.INDEXES user_updates .indexes.object_id和sys.dm_db_index_usage_stats.index_id = sys.indexes.index_id 其中,OBJECT_NAME(sys.dm_db_index_usage_stats.object_id)不爲空,DB_ID('MY_DB')= database_id order by tablo –

回答

0

索引碎片應該幫助 - 看行和碎片數量:

SELECT 
    B.name AS TableName 
    ,C.name AS IndexName 
    ,C.fill_factor AS IndexFillFactor 
    ,D.rows AS RowsCount 
    ,A.avg_fragmentation_in_percent 
    ,A.page_count 
FROM 
    sys.dm_db_index_physical_stats(DB_ID(),NULL,NULL,NULL,NULL) A 
INNER JOIN 
    sys.objects B 
ON 
    A.object_id = B.object_id 
INNER JOIN 
    sys.indexes C 
ON 
    B.object_id = C.object_id AND A.index_id = C.index_id 
INNER JOIN 
    sys.partitions D 
ON 
    B.object_id = D.object_id AND A.index_id = D.index_id 
WHERE 
    C.index_id > 0 
order by 
    avg_fragmentation_in_percent desc 

PFE:感謝Neeraj Dwivedi在SQL中央