Sql-server – SQL Server – How to get corrupted rows id

sql server

I have a corrupted SQL Server database.

Running command

dbcc checkdb repair_allow_data_loss

tells me there would be data loss.

Error:

Msg 8964, Sev 16, State 1, Line 1
Table error: Object ID 165575628, index ID 1, partition ID 72057594120568832, alloc unit ID 72057594040483840 (type LOB data). The off-row data node at page
(1:269), slot 4, text ID 1116865298432 is not referenced. [SQLSTATE 42000]

How can I get the corrupted rows id before to run that command?

Thanks

Best Answer

There is probably a better way, because the following is time consuming, but I know it will work: First, backup your corrupted database. Second, try to bcp out the data. As it copies the data out, it will display on the screen the number of rows copied. When it errors, note the number of rows copied. Those are all the rows prior to hitting the corruption. Let's say the last entry of number of rows copied prior to hitting the error is 1078466. You narrow down your bcp command by adding -F 1078566 -L 1080466. This will skip over 100 rows and try to copy out the next 1900 rows. If it succeeds, then you know that the corruption is somewhere between rows 1078466 and 1078566. Adjust your -F and -L to narrow down your search. If it errors, then you know that the corruption is after 1078566. Adjust your -F and -L to narrow down your search. Repeat as necessary to locate your corrupted rows.