Reconstruir / reorganizar índices
SQL ServerMantenimientoComando
-- Rebuild (high fragmentation > 30%). ONLINE requires Enterprise:
ALTER INDEX IX_Customer_Email ON dbo.Customer
REBUILD WITH (ONLINE = ON, MAXDOP = 4, SORT_IN_TEMPDB = ON);
-- All indexes of a table:
ALTER INDEX ALL ON dbo.Customer REBUILD WITH (FILLFACTOR = 90);
-- Reorganize (moderate fragmentation 5-30%, always online, can be stopped):
ALTER INDEX IX_Customer_Email ON dbo.Customer REORGANIZE;Qué hace
REBUILD recrea el índice desde cero (elimina por completo la fragmentación y refresca las estadísticas); REORGANIZE compacta el nivel hoja en el sitio (ligero, no bloqueante).
Cuándo usarlo
REORGANIZE para una fragmentación del 5-30%, REBUILD por encima del 30%. En ventanas de mantenimiento para tablas grandes.
Precaución
ONLINE = ON solo está disponible en Enterprise/Developer; use OFF en Standard (la tabla se bloquea). REBUILD genera mucho log y necesita espacio. MAXDOP y SORT_IN_TEMPDB afectan al uso de recursos.