TO CHECK SQL DATABASE UTILIZATION AND FRAGMENTATION

BELOW IS USED FOR FRAGMENTATION :

SELECT OBJECT_NAME(a.object_id) AS table_name, b.name AS index_name,
index_type_desc
AS index_type, index_depth, index_level
, avg_fragmentation_in_percent AS fragmentation FROM sys.dm_db_index_physical_stats ( db_id('snippetkey_For_Testing'), OBJECT_ID('dbo.'), NULL, NULL, 'DETAILED')a
INNER JOIN sys.indexes b ON a.object_id = b.object_id AND a.index_id = b.index_id

Below is Utilization
SELECT DB_NAME(database_id),
SUM(num_of_bytes_read) + SUM(num_of_bytes_written) AS bytes
FROM sys.dm_io_virtual_file_stats(NULL, NULL)
GROUP BY database_id
ORDER BY SUM(num_of_bytes_read) + SUM(num_of_bytes_written) DESC

select * FROM sys.dm_io_virtual_file_stats(NULL, NULL)

Comments