I would like to rebuild indexes on the some tables of a database then rebuild indexes where fragmentation is higher than %30 so I tried to do it by using
ALTER INDEX [AK_SalesOrderDetail_rowguid]
REBUILD WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE =
OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON,
SORT_IN_TEMPDB = ON, ONLINE = OFF )
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?
I dont know it may be script and sp then I will make a daily job for these indexes to rebuilt but first of all, I need to simplify it..I am rebuilding indexes in the list resulting where fragmentation>30 after executing like below with step by step..
i.name as IndexName,
OBJECT_SCHEMA_NAME(ps.object_id) as ObjectSchemaName,
OBJECT_NAME (ps.object_id) as ObjectName,
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