Disable|Enable Index

  • Hi Experts,

    I read in a post that during BCP,BULK INSERT kind of operation we can disable the index using

    ALTER INDEX [IX_StoreContact_ContactTypeID] ON Sales.StoreContact DISABLE

    and can re-enable it using

    ALTER INDEX [IX_StoreContact_ContactTypeID] ON Sales.StoreContact REBUILD

    My doubt is whats the difference it makes if we are rebuilding the index at the end? I mean rebuild is just like dropping and recreating index so why cant we drop and recreate instead of disable? Do we have any advantage in disabling?

    Thanks IN Advance

  • It is the same you are correct, but with disable / rebuild, you dont need to know the definition of the index to recreate it.

  • Thanks Antony for the quick reply.

    Is that the only advantage?

  • Yes, as disable drops the B-Tree of the index, but leaves the meta data in place, so the only way to get the index enabled again is rebuild, to rebuild the tree.

    Drop obivously drops the tree and the meta data, so you need to know the name of the index, the columns of the index etc etc in order to re-create it.

  • Thanks alot Anthony..

    Those details really helps in understanding exactly what happens..

    Thanks Again

  • Just don't try and disable the clustered index. There's a large difference there between dropping and disabling.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks Gail,

    Can you please help me in understanding the difference? or docs or link is highly appreciated.

  • Did you look in Books Online?

    Guidelines for Disabling Indexes and Constraints

    Disabling Clustered Indexes

    The following additional guidelines apply to disabling clustered indexes:

    The data rows of the disabled clustered index cannot be accessed except to drop or rebuild the clustered index. This means the following:

    These operations will fail: SELECT, UPDATE, DELETE, INSERT, CREATE INDEX, CREATE STATISTICS, UPDATE STATISTICS (on the index), and ALTER TABLE statements that modify table columns or constraints.

    These operations will succeed: CREATE VIEW, DROP VIEW, CREATE TRIGGER, DROP TRIGGER, DROP INDEX, ALTER TABLE ENABLE/DISABLE TRIGGER, TRUNCATE TABLE, and DROP TABLE.

    Nonclustered indexes cannot be created while the clustered index is disabled.

    Existing nonclustered indexes and XML indexes associated with the table are automatically disabled and cannot be accessed.

    All clustered and nonclustered indexes on views that reference the table are disabled. These indexes must be rebuilt just as those on the referenced table.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks a lot Gail.

    Seems like disable is pretty dangerous than drop & recreate. 🙂

  • No, not at all.

    Just like you wouldn't randomly drop the clustered index (unless you want your table inaccessible for a while and your log to bloat), you wouldn't randomly disable the clustered index.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks Gail.

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply