/* =====================================================================================================

모든 인덱스 다시 리빌드

======================================================================================================*/

DECLARE @i int, @sql varchar(1000)
DECLARE @tablename varchar(1000),@ownerName  varchar(1000)

SET @i = 1

DECLARE DB_Cursor CURSOR FOR
SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES  WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_SCHEMA, TABLE_NAME

OPEN DB_Cursor

FETCH NEXT FROM DB_Cursor
INTO @ownerName, @tablename
WHILE @@FETCH_STATUS = 0
BEGIN

SET @sql = 'ALTER INDEX ALL ON ' + @ownerName + '.' + @tablename + ' REBUILD WITH (PAD_INDEX = ON, FILLFACTOR = 90) '

EXEC (@sql)

PRINT CONVERT(VARCHAR, @i) + '__' + @ownerName + '.' + @tablename + '............ OK'

SET @i = @i + 1

 FETCH NEXT FROM DB_Cursor

INTO @ownerName, @tablename

 END

CLOSE DB_Cursor

DEALLOCATE DB_Cursor


/* =====================================================================================================

데이터베이스의 모든 통계 업데이트

======================================================================================================*/

SP_UPDATESTATS

'Database > Query' 카테고리의 다른 글

특정 문자열 포함하는 프로시저  (0) 2020.08.28
Full Scan, Index Scan Query  (0) 2020.08.28
INDEX 사용량  (0) 2020.08.28
INDEX 정보  (0) 2020.08.28
동적 쿼리2  (0) 2020.08.27

+ Recent posts