Last active
July 12, 2016 04:57
-
-
Save smarenich/8f378eedd9e663577ac203c6375a6de5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @Table VARCHAR(255) | |
DECLARE @cmd NVARCHAR(500) | |
DECLARE @fillfactor INT | |
SET @fillfactor = 95 | |
set @cmd = 'DECLARE TableCursor CURSOR FOR SELECT ''['' + table_catalog + ''].['' + table_schema + ''].['' + | |
table_name + '']'' as tableName FROM INFORMATION_SCHEMA.TABLES | |
WHERE table_type = ''BASE TABLE''' | |
-- create table cursor | |
EXEC (@cmd) | |
OPEN TableCursor | |
FETCH NEXT FROM TableCursor INTO @Table | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
SET @cmd = 'ALTER INDEX ALL ON ' + @Table + ' REBUILD WITH (FILLFACTOR = ' + CONVERT(VARCHAR(3),@fillfactor) + ')' | |
EXEC (@cmd) | |
FETCH NEXT FROM TableCursor INTO @Table | |
END | |
CLOSE TableCursor | |
DEALLOCATE TableCursor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment