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

dba.stackexchange https://dba.stackexchange.com/questions/261091

Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top