WorkaHolic

시스템상의 모든 인덱스를 재구성하는 프로시저

2010. 4. 8. 22:30
반응형

SET NOCOUNT ON
DECLARE TableList CURSOR FOR
 SELECT name
   FROM sysobjects
  WHERE type = 'U'
  ORDER BY name
DECLARE @table sysname
      , @ExecStr varchar(500)
 
OPEN TableList
FETCH NEXT FROM TableList INTO @table
WHILE @@FETCH_STATUS <> -1
BEGIN
   PRINT @table
   EXEC ('dbcc dbreindex(''' + @table + ''')')
   FETCH NEXT FROM TableList INTO @table
END
DEALLOCATE TableList

반응형