defragging indexes
DESCRIPTION
Defragging Indexes for beginnersTRANSCRIPT
![Page 1: Defragging Indexes](https://reader036.vdocuments.site/reader036/viewer/2022082811/55907d1f1a28ab46368b45e9/html5/thumbnails/1.jpg)
Defragging Indexes For Beginners
![Page 2: Defragging Indexes](https://reader036.vdocuments.site/reader036/viewer/2022082811/55907d1f1a28ab46368b45e9/html5/thumbnails/2.jpg)
Why we need to defrag indexes
• Fragmented indexes are ineffective• Ineffective indexes are slooooooow
![Page 3: Defragging Indexes](https://reader036.vdocuments.site/reader036/viewer/2022082811/55907d1f1a28ab46368b45e9/html5/thumbnails/3.jpg)
Over to the code….
We are going to:
• Create a database• Create a table • Load some data• Add an index• Fragment the index• Fix the index
![Page 4: Defragging Indexes](https://reader036.vdocuments.site/reader036/viewer/2022082811/55907d1f1a28ab46368b45e9/html5/thumbnails/4.jpg)
Demo...
![Page 5: Defragging Indexes](https://reader036.vdocuments.site/reader036/viewer/2022082811/55907d1f1a28ab46368b45e9/html5/thumbnails/5.jpg)
Which option is best?
• > 5% and < = 30% fragmentationALTER INDEX REORGANIZE
• > 30% fragmentationALTER INDEX REBUILD WITH (ONLINE = ON)
![Page 6: Defragging Indexes](https://reader036.vdocuments.site/reader036/viewer/2022082811/55907d1f1a28ab46368b45e9/html5/thumbnails/6.jpg)
Keep your indexes sweet
• Perform regular maintenance on your database, include index checks/defrags as part of the maintenance task.
• A tool such as Idera’s SQL Defrag Manager could be useful, but it is pricey.
• Write a script and set up a scheduled task to automate your index maintenance.
![Page 7: Defragging Indexes](https://reader036.vdocuments.site/reader036/viewer/2022082811/55907d1f1a28ab46368b45e9/html5/thumbnails/7.jpg)
Conclusion• Reorganize Index
− Peformed online− Does not lock for long periods− Does not block updates or other queries− Best option for fragmentation between 5% and
30%.• Rebuild Index
− Drops and recreates the index− Will give the best defragmentation results− Can be performed online or offline− Best option for fragmentation greater than 30%
• Maintenance− Monitor your index fragmentation− Fix fragmented indexes before they become a
problem
![Page 8: Defragging Indexes](https://reader036.vdocuments.site/reader036/viewer/2022082811/55907d1f1a28ab46368b45e9/html5/thumbnails/8.jpg)
Resources• Click on the Word icon to the right to access the SQL code and
notes used in the practical element of this session.
• Download AdventureWorks2008 DBs for free here: http://tinyurl.com/c6y6a3
• More info on fill factors over at the MSDN site: http://msdn.microsoft.com/en-us/library/aa933139(SQL.80).aspx
• Detailed information on Reorganize and Rebuild: http://msdn.microsoft.com/en-us/library/ms189858(SQL.90).aspx
• Great information on Indexes from Brad McGehee• http://tinyurl.com/mfx8h7
• Maintenance Options:• http://www.idera.com/Products/SQL-Server/SQL-defrag-manager
/• http://msdn.microsoft.com/en-us/library/aa258803(SQL.80).
aspx
Microsoft Office Word Document
![Page 9: Defragging Indexes](https://reader036.vdocuments.site/reader036/viewer/2022082811/55907d1f1a28ab46368b45e9/html5/thumbnails/9.jpg)
Website:www.aucklandsql.com
Mailing list:[email protected]
Blog:http://nzgirlgeek.blogspot.com
Email: [email protected]