In some companies it’s almost impossible to make a full index rebuild, because they have only a few hours of maintenance windows
You can adapt this script to rebuild a specific number of indexes during each day, during a specific hours. If you have several companies in a database you can even adapt it to rebuild each company at a specific hour of day.
This scripts only runs in SQL Server 2005. This script isn’t complete you have to adapt it to your current company and define fragmentation values.
Create a table to store indexes and values.
-- TABLE OF INDEXES
CREATE TABLE IndexFragList ( DatabaseId INT,IndexId INT,ObjectID INT,IndexName CHAR (255), AvgFrag DECIMAL,TableName VARCHAR(255) )
-- ############ SCRIPT #############################
DECLARE
-- Decide on the maximum fragmentation to allow
SELECT
SET
IF
-- CUSTOMIZE THIS-- IF CAN FILTER BY COMPANY, ETC
FETCH
CLOSE