MSSQL Tip: Rebuild Clustered Indexes
Rebuild clustered index in the database tables. This code uses cursor to run through user tables. Also it uses dbcc dbreindex command to rebuild index. Use this with care since each rebuild hangs table up.
declare tabcurs cursor for select name from sysobjects where xtype = 'u' open tabcurs declare @tname varchar(30) fetch next from tabcurs into @tname while @@fetch_status = 0 begin dbcc dbreindex(@tname) fetch next from tabcurs into @tname end close tabcurs deallocate tabcurs
Sunday, November 30, 2003 1:52 PM