I executed DBCC CHECKTABLE on one of my tables, and I got below error.
“table ‘tbl_students’ (ID 6589332541). Data row does not have a matching index row in the index ‘idx_tbl_students_id’ (ID 88). Possible missing or invalid keys for the index row matching.”
The above error is indicating the corruption of index “idx_tbl_students_id” so few records are missing.
If your index corrupted, there are two possible solutions. One is Restore your database backup and Second is Rebuild your corrupted indexes.
People are using REBUILD command for rebuilding the indexes, but in this article, I repaired the index using option REPAIR_REBUILD of DBCC.
You can use the REPAIR_REBUILD option with DBCC CHECKDB and DBCC CHECKTABLE. While executing those DBCC commands, you can repair corrupted indexes.
This can include quick repairs, such as repairing missing rows in non-clustered indexes, and more time-consuming repairs, such as rebuilding an index.
Following are example,
DBCC CHECKDB ('Database_Name', REPAIR_REBUILD)
DBCC CHECKTABLE ('Table_Name', REPAIR_REBUILD)
You can use below article and find script to rebuild all indexes of SQL Server Database:
Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.
If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.
I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.