Sql-server – Releasing space

disk-spacesql-server-2008-r2

We have a db table which contained a large amount of documents. These documents have now been stripped out and as this table will never grow to this size again we are looking to claim back this space.

From reading up on this the best solution appears to be:

Create new filegroup (called secondary-we currently only have primary)

Move all user tables into this new filegroup by dropping and recreating the clustered index

Is this the best solution? I assume I would then need to shrink the primary filegroup? Is so, what's the best way to do this?

Many thanks
Paul

Best Answer

All you would need to de-fragment the table by rebuilding the clustered index.

ALTER INDEX [IndexName] ON [YourTable] REBUILD

The clustered index on any table determines how it will be written to disk. When a bunch of deletes or re-writes occurs, the table becomes fragmented and wastes a lot of space. Doing this will restructure the data on the disk and should free up a lot of that wasted space.

I would say you could take it further by doing a database shrink however if the database is likely to re-grow to that size or larger, it would be a mistake to do that.