HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

Why disabling a clustered index makes the table inaccessible?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
clusteredwhytheinaccessiblemakesindexdisablingtable

Problem

When an index is disabled, the definition remains in the system catalog but is no longer used. SQL Server does not maintain the index (as data in the table changes), and the index cannot be used to satisfy queries. If a Clustered Index is disabled, the entire table becomes inaccessible.

Why isn't it possible to access the data directly from the table discarding the B-tree? (most likely by scanning the table row by row) Wouldn't that be more appropriate than making the data completely inaccessible?

It's a purely theoretical question - I would never actually do that. It's not a scenario, nor a to-do thing, I just want to know why thing goes that way, consider it an internals question.

Solution

why isn't it possible to access the data directly from the table discarding the B-tree?
(most likely by scanning the table row by row)
wouldn't that be more appropriate than inaccessible data at all?

To answer your question, Indexing basics comes more handy -- An index is made up of a set of pages (index nodes) that are organized in a B-tree structure. This structure is hierarchical in nature, with the root node at the top of the hierarchy and the leaf nodes at the bottom. For more details refer here.

Also, as many people have described, Clustered Indexes == Original tables which are physically ordered with one or more keys or columns. So, when a clustered Index is disabled, its data rows cannot be accessed. You wont be able to Insert any data (for Non Clustered Index the Insert will succeed -- but that is not entirely related to this post -- as here the discussion is of Clustered Index) as well or neither Reorganize operation will work.

Below will explain you in detail :

we will use Adventureworks database to see the effect of disabling the CLUSTERED Index.

Now check the row count in the table:

Now disable the Clustered Index

Now select the row count from the table. This time it will error out with below message:

Even the reorganize operation does not work !!

Now rebuild the Clustered Index and it should work fine.

Select the table to see if we can access the data

So the bottom line is that, if we disable the Clustered Index, then Data in the table still exists, but will not be accessible for anything other than Drop or REBUILD operations. All related Non-clustered Indexes and views will be unavailable as well as Foreign Keys referencing the table will be disabled and there by leading the FAILURE for all the queries that are referencing the table.

Note: There is no option to ENABLE the Index. You have to REBUILD it.

Context

StackExchange Database Administrators Q#41519, answer score: 11

Revisions (0)

No revisions yet.