Sql-server – How to use the smallest amount database file space to rebuild an index on Mircosoft SQL Server Express due to the 10GB limit

disk-spaceindex-maintenancesql server

How do I use the smallest amount of database file space to rebuild an index on Mircosoft SQL Server Express due to the 10GB limit

I have a database file size of 7GB but I have two indexes that are on the two largest tables that are very fragmented
enter image description here

If I try to rebuild the index PK_Sale_Dtl the file size balloons to 10GB and the rebuild fails and I get nowhere but if I drop the index and recreate it the file doesn't barely increase at all

Why is this? And which is better rebuild or recreate index?

Best Answer

The reason is that index rebuild means creating a new index under covers and then dropping the old index. I.e., while the operation is running you need twice the amount of storage available. If that isn't doable for you, you have basically two options:

Do it yourself in the opposite order: Drop first and then create.

Or do REORGANIZE instead of REBUILD.