Query - How to Check Index Seek, Index Scan

Below
query give us Index read, Write, Seek, Scan and Index Size.



SELECT 
o.name AS TableName, 

i.name AS Indexname, 

i.is_primary_key AS PrimaryKey, 
s.user_seeks + s.user_scans + s.user_lookups AS NumOfReads, 
s.user_updates AS NumOfWrites, 
s.user_seeks , s.user_scans , s.user_lookups,
(SELECT SUM(p.rows) FROM sys.partitions p WHERE p.index_id = s.index_id AND s.object_id = p.object_id) AS TableRows 
FROM sys.dm_db_index_usage_stats s 
INNER JOIN sys.indexes i ON i.index_id = s.index_id AND s.object_id = i.object_id 
INNER JOIN sys.objects o ON s.object_id = o.object_id 

INNER JOIN sys.schemAS c ON o.schema_id = c.schema_id 

WHERE OBJECTPROPERTY(s.object_id,'IsUserTable') = 1 
AND s.database_id = DB_ID() 




























 



SELECT
OBJECT_SCHEMA_NAME(i.OBJECT_ID) AS SchemaName,
OBJECT_NAME(i.OBJECT_ID) AS TableName,
i.name AS IndexName,
i.index_id AS IndexID,
SUM(a.used_pages) AS 'Indexsize(KB)'
FROM sys.indexes AS i
JOIN sys.partitions AS p ON p.OBJECT_ID = i.OBJECT_ID AND p.index_id = i.index_id
JOIN sys.allocation_units AS a ON a.container_id = p.partition_id
where OBJECT_SCHEMA_NAME(i.OBJECT_ID)<>'sys'
GROUP BY i.OBJECT_ID,i.index_id,i.name
ORDER BY OBJECT_NAME(i.OBJECT_ID),i.index_id

Index Seek, Index Scan
























Comments