VB and VBA Users Source Code: Rebuild all the Indexes on a SQL Server database
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Rebuild all the Indexes on a SQL Server database
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Monday, April 30, 2001
Hits:
504
Category:
Database/SQL/ADO
Article:
To correct fragmentation and FILLFACTOR problems you should rebuild you indexes on a regular basis. The following script rebuilds all the indices on a SQL Server 7 database. Note, it is advised that you DO NOT run this script will other users are logged on to the database. DECLARE @TableName varchar(255) DECLARE TableCursor CURSOR FOR SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' DECLARE @Command varchar(255) OPEN TableCursor FETCH NEXT FROM TableCursor INTO @TableName WHILE @@FETCH_STATUS = 0 BEGIN PRINT "Reindexing " + @Tablename DBCC DBREINDEX(@TableName) FETCH NEXT FROM TableCursor INTO @TableName END CLOSE TableCursor DEALLOCATE TableCursor
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder