SQL Server 2016 – How to Rebuild Index at Partition Level

index-maintenancepartitioningsql serversql-server-2016

We have functionality in SQL Server to rebuild indexes at partition level using below command

ALTER INDEX IX_name ON table REBUILD PARTITION=68

In non-partitioned table we disable the indexes, load the data and rebuild the indexes after the data load complete. Here we disable the indexes prior to data load so that indexes will not be processed while data insertion to table is happening.

How can I do the same process for a partitioned table? If i disable indexes on a partitioned table before data load, and run the rebuild partition command after the data load is complete, it won't work, saying disabled indexes cannot be rebuilt.

Microsoft SQL Server 2016 (SP2) (KB4052908) – 13.0.5026.0 (X64) Enterprise Edition.

Best Answer

How can I do the same process for a partitioned table?

While you can rebuild a single partition, you can't disable just one partition.

So you would use a staging table on the same partition scheme. Disable its indexes, load it, rebuild the indexes, and then switch one or more partitions into the main table.