DEFINITIONS

Definitions More Info.
Definition ID37
TitleSQL
CategorySCRIPT
DefinitionIndex fragmentation
Definition Description-- ISMAIL ADAR
SELECT TOP 200
DB_NAME() AS DatabaseName
, SCHEMA_NAME(o.schema_id) AS SchemaName
, OBJECT_NAME(s.[object_id]) AS TableName
, i.name AS IndexName
,partition_number AS partitionnum
,page_count as PageCnt
, ROUND(s.avg_fragmentation_in_percent,2) AS [Fragmentation %]
FROM sys.dm_db_index_physical_stats (db_id(),null,null,null,null) s
INNER JOIN sys.indexes i ON s.[object_id] = i.[object_id]
AND s.[index_id] = i.index_id
INNER JOIN sys.objects o ON i.[object_id] = o.[object_id]
WHERE s.[database_id] = DB_ID()
AND i.[name] IS NOT NULL
AND OBJECTPROPERTY(s.[object_id],'IsMsShipped') = 0
ORDER BY [Fragmentation %] DESC


-- BENIM BASKA YERDEN BULDUGUM
SELECT object_name(ps.object_id) as [name]
, ps.index_id
,avg_fragmentation_in_percent
, fragment_count
, avg_fragment_size_in_pages
, page_count
, avg_page_space_used_in_percent
,range_scan_count
, singleton_lookup_count
FROM sys.dm_db_index_physical_stats(DB_ID(),null,null,null,'LIMITED') ps
CROSS APPLY sys.dm_db_index_operational_stats(DB_ID(),null,null,null) os
WHERE ps.object_id = os.object_id and ps.index_id = os.index_id and ps.index_level = 0
AND ps.avg_fragmentation_in_percent > 10
ORDER By [name], index_id
RecordBycunay
Record Date15-02-2012 15:08:26
Düzenle
Kopyala
Sil