Link to home
Start Free TrialLog in
Avatar of chetan1981
chetan1981

asked on

defrag all tables in all databases

any one has a script to derfrag all tables in all databases?? Inned to run DBCC showcontig and not DMV as it needs to tun on both sql 2k and sql 2k5
ASKER CERTIFIED SOLUTION
Avatar of chapmandew
chapmandew
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I apologize, I saw the 2005 but missed the comment about SQL Server 2000. I would definitely use the script that is at the Microsoft site linked above for both. This will work in both 2000 and 2005 and you can decide which tables to or not to defragment with the maxfrag percentage to avoid doing work you don't need to do.

This is the premise that Michelle based her script off of. I would even suggest using the Microsoft script for SQL Server 2000 and her script for SQL Server 2005, especially if you are on enterprise edition and want to take advantage of online index rebuilds. Her script also addresses a statistics rebuild which should be done during maintenance as well.