Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Selective Defrag/Reindex and Log

By dataninja, 2004/11/11

SQL 2000 Only

This script will create a stored procedure and a table in the master database. Simply run the stored procedure and supply a database name as a parameter. It will do the following:

1. Gather/Log DBCC SHOWCONTIG statistics (pre defrag)
2. Defragment all user indexes in the database
3. Gather/Log DBCC SHOWCONTIG statistics (post defrag)
4. DBCC DBREINDEX for all indexes that have %10 logical fragmentation
5. Gather/Log DBCC SHOWCONTIG statistics for reindexed tables.

All activity is logged in [master].[dbo].[fragreport]

You can create a job to schedule this and use the fragreport to identify problem areas with your indexes/database use.

Have fun!

New Version - works with table not owned by dbo

Total article views: 2046 | Views in the last 30 days: 10
 
Related Articles
FORUM

Defragment the indexes in a database - NOT WORKING

Using DBCC SHOWCONTIG and DBCC INDEXDEFRAG to defragment the indexes in a database

FORUM

job for index defrag

job for index defrag

SCRIPT

Defragment all indexes on Database

It finds the Indexes on database which needs to be Defragmented and Rebuilds those indexes. Only you...

FORUM

How to charch the index defrag

I am using DBCC SHOWCONTIG to check the index defrag, but I want to get only index that are defrag n...

FORUM

DBCC SHOWCONTIG WITH TABLERESULTS, ALL_INDEXES question

DBCC SHOWCONTIG WITH TABLERESULTS, ALL_INDEXES question

 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones