Has anyone written or seen an SQL query that can automatically defragment all the tables? I found that a ton of my Orion DB have over 90% fragmentation and more than half of the tables are over 75%.
Here is a more in depth defrag you can run from SQL Studio
DECLARE @CoreTable VARCHAR(255)
DECLARE CoreCursor
CURSOR FOR
SELECT table_name
FROM information_schema.tables
WHERE table_type = 'base table'
OPEN CoreCursor
FETCH NEXT
FROM CoreCursor INTO @CoreTable
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT 'Reindexing Table: ' + @CoreTable
DBCC DBREINDEX(@CoreTable, '', 80)
FETCH NEXT
FROM CoreCursor INTO @CoreTable
END
CLOSE CoreCursor
DEALLOCATE CoreCursor
SolarWinds solutions are rooted in our deep connection to our user base in the THWACK® online community. More than 195,000 members are here to solve problems, share technology and best practices, and directly contribute to our product development process.