Rebuild Indexes in SQL server using cursor

Disclaimer:Hey Guys, this post contains affiliate link to help our reader to buy best product\service for them. It helps us because we receive compensation for our time and expenses.

Infrastructure: This has been run and tested successfully on SQL 2005 and onward.

Scenario:  In DBAs life, this is most important and weekly\daily kind of stuffs.

Due to highly uses, insert, update, delete command on databases, indexes got fragmented and high fragmentation results into worst database performance.

So being the DBA its our responsibility to find out fragmented indexes and rebuild them during maintenance window.

Please keep in mind, always perform these kind of stuffs on UAT and then move to Prod server.

In this case, rebuilding indexes with the help of cursor can be much handy.


To know and understand about the indexes click here

Please click here to download rebuild heap tables script.

Hope this helps!