CREATE PROCEDURE spReindexAllTables AS
SET NOCOUNT ON
DECLARE @TblName char(100)
DECLARE IdxCursor CURSOR FOR SELECT name FROM sysobjects WHERE type='U'
OPEN IdxCursor
FETCH NEXT FROM IdxCursor INTO @TblName
WHILE @@FETCH_STATUS=0 BEGIN
DBCC DBREINDEX(@TblName)
FETCH NEXT FROM IdxCursor INTO @TblName
END
CLOSE IdxCursor
DEALLOCATE IdxCursor
GO
The procedure above select all table names from the sysobjects table and loop through each table then executes the reindex command on it.
For More SQL Tips & Tricks, subscribe now.
0 comments:
Post a Comment