Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Defragging Indexes


Published on

Defragging Indexes for beginners

  • Be the first to comment

  • Be the first to like this

Defragging Indexes

  1. 1. Defragging Indexes For Beginners<br />
  2. 2. Why we need to defrag indexes<br />Fragmented indexes are ineffective<br />Ineffective indexes are slooooooow<br />
  3. 3. Over to the code….<br />We are going to: <br />Create a database<br />Create a table <br />Load some data<br />Add an index<br />Fragment the index<br />Fix the index<br />
  4. 4. Demo...<br />
  5. 5. Which option is best?<br />> 5% and < = 30% fragmentation<br />ALTER INDEX REORGANIZE<br />> 30% fragmentation<br />ALTER INDEX REBUILD WITH (ONLINE = ON)<br />
  6. 6. Keep your indexes sweet<br />Perform regular maintenance on your database, include index checks/defrags as part of the maintenance task.<br />A tool such as Idera’s SQL Defrag Manager could be useful, but it is pricey.<br />Write a script and set up a scheduled task to automate your index maintenance.<br />
  7. 7. Conclusion<br />Reorganize Index<br />Peformed online<br />Does not lock for long periods<br />Does not block updates or other queries<br />Best option for fragmentation between 5% and 30%.<br />Rebuild Index<br />Drops and recreates the index<br />Will give the best defragmentation results<br />Can be performed online or offline<br />Best option for fragmentation greater than 30%<br />Maintenance<br />Monitor your index fragmentation<br />Fix fragmented indexes before they become a problem<br />
  8. 8. Resources<br />Click on the Word icon to the right to access the SQL code and notes used in the practical element of this session. <br />Download AdventureWorks2008 DBs for free here:<br />More info on fill factors over at the MSDN site:<br />Detailed information on Reorganize and Rebuild:<br />Great information on Indexes from Brad McGehee<br /><br />Maintenance Options:<br /><br /><br />
  9. 9. Website:<br /><br />Mailing list:<br /><br />Blog:<br /><br />Email: <br /><br />