{{ model.title }}

by {{ model.createdBy }}
Rebuilds all indexes in a database
code
DECLARE @tableName varchar(255)
DECLARE tableCursor CURSOR FOR 
	SELECT table_name FROM information_schema.tables
	WHERE table_name NOT LIKE '%MigrationHistory%' AND table_type = 'BASE TABLE';

OPEN tableCursor 
FETCH NEXT FROM tableCursor INTO @tableName 
WHILE @@FETCH_STATUS = 0 
BEGIN
	PRINT @tableName
	EXEC('ALTER INDEX ALL ON [' + @tableName + '] REBUILD')
	FETCH NEXT FROM TableCursor INTO @tableName 
END
CLOSE tableCursor 
DEALLOCATE tableCursor