but it is very hard to do it for every index (where fragmention>30) on some tables for a special database step by step and it takes too long time so how can I rebuild the indexes where fragmentation>30 on tables for a special database by simple way with the index syntax like this above?
USE [AdventureWorks] GO ALTER INDEX [AK_SalesOrderDetail_rowguid] ON [Sales].[SalesOrderDetail] REBUILD WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, SORT_IN_TEMPDB = ON, ONLINE = OFF ) GO
Use BTN_DB_Labordaten GO SELECT ps.object_id, i.name as IndexName, OBJECT_SCHEMA_NAME(ps.object_id) as ObjectSchemaName, OBJECT_NAME (ps.object_id) as ObjectName, ps.avg_fragmentation_in_percent FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL , NULL, 'LIMITED') ps INNER JOIN sys.indexes i ON i.object_id=ps.object_id and i.index_id=ps.index_id WHERE avg_fragmentation_in_percent > 5 AND ps.index_id > 0 ORDER BY avg_fragmentation_in_percent desc
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.