We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ed3a7c6 commit 5366e87Copy full SHA for 5366e87
sql-queries-index/index-rebuild/rebuild_all_index_in_db.sql
@@ -0,0 +1,24 @@
1
+USE University;
2
+GO
3
+
4
+DECLARE @TableName NVARCHAR(255);
5
+DECLARE @SQL NVARCHAR(MAX);
6
7
+DECLARE table_cursor CURSOR FOR
8
+SELECT QUOTENAME(SCHEMA_NAME(t.schema_id)) + '.' + QUOTENAME(t.name)
9
+FROM sys.tables t
10
+WHERE t.is_ms_shipped = 0;
11
12
+OPEN table_cursor;
13
+FETCH NEXT FROM table_cursor INTO @TableName;
14
15
+WHILE @@FETCH_STATUS = 0
16
+BEGIN
17
+ SET @SQL = 'ALTER INDEX ALL ON ' + @TableName + ' REBUILD WITH (FILLFACTOR = 90, SORT_IN_TEMPDB = ON);';
18
+ PRINT 'Rebuilding indexes on: ' + @TableName;
19
+ EXEC sp_executesql @SQL;
20
+ FETCH NEXT FROM table_cursor INTO @TableName;
21
+END;
22
23
+CLOSE table_cursor;
24
+DEALLOCATE table_cursor;
0 commit comments