timtownsend

Rebuild indexes in Microsoft SQL

Mar 12th, 2025
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.39 KB | Fixit | 0 0
  1. DECLARE @TableName VARCHAR(255)
  2.  
  3. DECLARE TableCursor CURSOR FOR
  4. SELECT TABLE_NAME FROM information_schema.TABLES
  5. WHERE table_type = 'base table'
  6.  
  7.  
  8. OPEN TableCursor
  9. FETCH NEXT FROM TableCursor INTO @TableName
  10.  
  11. WHILE @@FETCH_STATUS = 0
  12. BEGIN
  13. DBCC DBREINDEX(@TableName,' ',90)
  14. FETCH NEXT FROM TableCursor INTO @TableName
  15. END
  16.  
  17.  
  18. CLOSE TableCursor
  19.  
  20. DEALLOCATE TableCursor
Advertisement
Add Comment
Please, Sign In to add comment