Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
One way to solve this is to shrink the database and reindex all tables to fix the indexes fragmentation: DBCC SHRINKDATABASE (TheDatabase); GO -- reindexing all tables to optimize performance ...
Answer
#1: Initial revision
One way to solve this is to shrink the database and reindex all tables [to fix the indexes fragmentation](https://www.brentozar.com/archive/2009/08/stop-shrinking-your-database-files-seriously-now/): DBCC SHRINKDATABASE (TheDatabase); GO -- reindexing all tables to optimize performance after the DB shrink declare @TableSchema varchar(255) DECLARE @TableName varchar(255) DECLARE TableCursor CURSOR FOR SELECT TABLE_SCHEMA, table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_type = 'BASE TABLE' OPEN TableCursor FETCH NEXT FROM TableCursor INTO @TableSchema, @TableName WHILE @@FETCH_STATUS = 0 BEGIN declare @TN varchar(255) = @TableSchema + '.' + @TableName print 'Reindexing ' + @TN DBCC DBREINDEX(@TN,' ',90) FETCH NEXT FROM TableCursor INTO @TableSchema, @TableName END CLOSE TableCursor DEALLOCATE TableCursor GO I am not sure if there are any side effects after performing this.