Unable to publish batch class - Fatal database error

PROBLEM

Can not Publish Batch Class:

"Fatal database error - Can't delete or change record. Since related records exist in table The DELETE statement conflicted with the REFERENCE constraint "BatchDocumentPart4"".

This is caused by the orphaned records in the Batch Document tables

SOLUTION

To resolve the problem is to run the following SQL query directly on the Kofax Capture Database by using KI easyQuery2022.1 Tool

DELETE FROM BatchDocumentPartialRel
WHERE BatchID NOT IN (SELECT ExternalBatchID FROM BatchCatalog)

NOTE: It is strongly recommended to back up the database prior to running the SQL query.