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?


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.


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

Rebuilding an index leaves the existing index in place, builds a new one, and drops the old one.

So if you don't need to have the index available for queries during the rebuild, drop/create or disable it before rebuilding it.

Disabling an index is just like dropping it, but you don't have to remember the index DDL. eg

alter index ix_SomeIndex on SomeTable disable;
alter index ix_SomeIndex on SomeTable rebuild;
  • 1
    Disabling an index does leave it's associated statistics object available though (and it will continue to be updated). – Paul White Mar 7 '20 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.