The attached four scripts will create a daily maintenance plan to rebuild and reorganize fragmented indexes in SSMS (SQL Server Management Studio). Run the scripts in order, the resulting plan will be found under SQL Server Agent.
The default scheduling is for 2:15 AM, however that can be adjusted. The settings will reorganize at 50% fragmentation and rebuild at 80%.
In many cases it is helpful to adjust the plan to be more proactive and reorganize at 10%, rebuild at 20% fragmentation as shown below.
If the settings are too loose, indexes will not be rebuilt until they are already too fragmented.