Created
April 8, 2016 17:36
-
-
Save howellcc/3abfda745c6de9f69b89472108676073 to your computer and use it in GitHub Desktop.
[SQL] Reorganize every table in every schema in a database.
This file contains hidden or 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
USE --DATABASE NAME | |
DECLARE @TableName varchar(255) | |
DECLARE @TableSchema varchar(255) | |
DECLARE @FULLNAME varchar(512) | |
DECLARE TableCursor CURSOR FOR | |
SELECT table_name, table_schema FROM information_schema.tables | |
WHERE table_type = 'base table' | |
OPEN TableCursor | |
FETCH NEXT FROM TableCursor INTO @TableName, @TableSchema | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
SET @FULLNAME = @TableSchema + '.' + @TableName | |
DBCC DBREINDEX(@FULLNAME,' ',90) | |
FETCH NEXT FROM TableCursor INTO @TableName, @TableSchema | |
END | |
CLOSE TableCursor | |
DEALLOCATE TableCursor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment