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

519 views

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: http://tinyurl.com/c6y6a3<br />More info on fill factors over at the MSDN site: http://msdn.microsoft.com/en-us/library/aa933139(SQL.80).aspx<br />Detailed information on Reorganize and Rebuild: http://msdn.microsoft.com/en-us/library/ms189858(SQL.90).aspx<br />Great information on Indexes from Brad McGehee<br />http://tinyurl.com/mfx8h7<br />Maintenance Options:<br />http://www.idera.com/Products/SQL-Server/SQL-defrag-manager/<br />http://msdn.microsoft.com/en-us/library/aa258803(SQL.80).aspx<br />
  9. 9. Website:<br />www.aucklandsql.com<br />Mailing list:<br />announce@aucklandsql.com<br />Blog:<br />http://nzgirlgeek.blogspot.com<br />Email: <br />amanda@aucklandsql.com<br />

×