Category Archives: Indexes

Query to Check Fragmentation and rebuild index in a database

Below query checks fragmentation level (>30%) per table which has clustered or non-clustered index and provides you the query to perform ONLINE rebuild of that index.The fragmentation level of the table which has the highest number of rows is displayed on top. Use [database_name] SELECT OBJECT_SCHEMA_NAME(ind.OBJECT_ID) + ‘.’ + OBJECT_NAME(ind.OBJECT_ID) AS TableName, ind.name AS IndexName, indexstats.index_type_desc AS IndexType,… Read More »