Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL 6.5: Rebuilding Indexes

Status
Not open for further replies.

Gussy

MIS
Aug 11, 2000
3
0
0
US
Help..Help..Did anyone knows the procedure to rebuild Indexes: Using SQL Enterprise Manager or executing a batch Script from DOS command Line?..Please i need an answer ASAP....Thanks.....
 
Rebuilding Indexes Tips<br>Periodically (weekly or monthly) perform a database reorganization on all the indexes on all the tables in your database. This will rebuild the indexes so that the data is no longer fragmented. Fragmented data can cause SQL Server to perform unnecessary data reads, slowing down SQL Server's performance.<br>If you do a reorganization on a table with a clustered index, any non-clustered indexes on that same table will automatically be rebuilt.<br>Database reorganizations can be done scheduling SQLMAINT.EXE to run using the SQL Server Agent, or if by running your own custom script via the SQL Server Agent (see below). Unfortunately, the DBCC DBREINDEX command will not automatically rebuild all of the indexes on all the tables in a database, it can only work on one table at a time. But if you run the following script, you can index all the tables in a database with ease:<br>--Script to automatically reindex all tables in a database<br><br>USE DatabaseName --Enter the name of the database you want to reindex<br><br>DECLARE @TableName varchar(255)<br><br>DECLARE TableCursor CURSOR FOR<br>SELECT table_name FROM information_schema.tables<br>WHERE table_type = 'base table'<br><br>OPEN TableCursor<br><br>FETCH NEXT FROM TableCursor INTO @TableName<br>WHILE @@FETCH_STATUS = 0<br>BEGIN <br>PRINT &quot;Reindexing &quot; + @TableName<br>DBCC DBREINDEX(@TableName,' ',90)<br>FETCH NEXT FROM TableCursor INTO @TableName<br>END<br><br>CLOSE TableCursor<br><br>DEALLOCATE TableCursor<br>The script will automatically reindex every index in every table of any database you select, and provide a fillfactor of 90%. You can substitute any number you want for the 90 in the above script.<br><br><br>Ok. I hope you enjoy this!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top