If you’re getting SQL Server error 8655 that reads something like “The query processor is unable to produce a plan because the index ‘PK__Employee__7AD04FF1A39ECAB1’ on table or view ‘Employees’ is disabled“, it’s probably because the clustered index for the table is disabled.
When a table’s clustered index is disabled, we can’t access the data in the table.
As Microsoft states:
Disabling a clustered index on a table prevents access to the data. The data still remains in the table, but is unavailable for data manipulation language (DML) operations until the index is dropped or rebuilt.
To fix this issue, enable the table’s clustered index. This will typically be the primary key index (unless you’ve specified another clustered index for the table).
Example of Error
Suppose we disable the clustered index for a table:
ALTER INDEX ALL ON Employees DISABLE;
Here, I disabled all indexes, including the clustered index.
Now when we use a DML statement to access the table, we get an error:
SELECT * FROM Employees;
Output:
Msg 8655, Level 16, State 1, Line 1
The query processor is unable to produce a plan because the index 'PK__Employee__7AD04FF1A39ECAB1' on table or view 'Employees' is disabled.
This error message tells us the exact reason for the error, as well as the exact index that’s disabled.
Solution
By now you’ve probably already figured out how to fix this issue. To fix this issue we must enable the clustered index for the table.
To enable an index, we use the ALTER INDEX
statement with the REBUILD
option.
So to rebuild all indexes on the table, we can use the ALL
keyword:
ALTER INDEX ALL ON Employees REBUILD;
Or to re-enable just the clustered index, we can name it explicitly:
ALTER INDEX PK__Employee__7AD04FF1A39ECAB1 ON Employees REBUILD;
After doing this, we will be able to access the data again without incurring the error.