Back to FAQ

Copilot

Open Copilot share

Violation of PRIMARY or UNIQUE KEY constraint 'INTEG_199' on table 'BATCH'

This error occurs when TurboCASH attempts to insert a duplicate row into the BATCH table (commonly a duplicate BATCHID or DOCUMENTNO) while reversing a batch. The database prevents duplicates and raises this constraint violation.

Step-by-step fix

  1. Check for duplicate BATCHID (Advanced)
    Use the SQL browser or an external tool (IBExpert, FlameRobin) and run:
    SELECT * FROM BATCH WHERE BATCHID = <ID causing error>;
    If the reversal tries to reuse an existing BATCHID, adjust the ID (or sequence) so a new unique ID is generated.
  2. Inspect DOCUMENTNO (Advanced)
    TurboCASH may reuse a DOCUMENTNO. Find duplicates with:
    SELECT DOCUMENTNO FROM BATCH GROUP BY DOCUMENTNO HAVING COUNT(*) > 1;
    If duplicates exist, rename or adjust the document number on the original batch before reversing.
  3. Use "Reverse posted batch/document" carefully (Recommended)
    Ensure you are not reversing a batch that has already been reversed or partially reversed. Partial reversals can leave data in a state that triggers key violations.
    Example workflow (open books and reverse a batch):
    1. Open the affected set of books.
    2. Setup > Global Processes > Reverse Batches.
    3. Try and reverse the set of books to see the error message.
    4. Now go back to the list of posted batches
    5. Select the posted batch from the list and double-click it to view entries.
    6. Click any entry in the batch, then click the Fix Unique ID button.
    7. After success, go to Default > Batch Entry to re-open the corrected batch.
    Images (if present) will show the screens and success messages.
    Open Reverse Batches screen Constraint error message Batch entries list Fix Unique ID success Batch now opens in Batch Entry
  4. Clear temporary or stuck entries
    Use Setup > Global Processes > Clear / Reset to run a cleanup only if you are confident no critical data will be lost. Always back up your books first.
  5. Manual reversal (workaround)
    If the automated reversal keeps failing, create a manual reversing journal entry: - Recreate the original batch amounts with opposite signs (debit ↔ credit). - This avoids invoking the automated reversal logic that triggers the key violation.

Why this happens

TurboCASH enforces unique constraints on identifiers. If the reversal process does not generate a new unique BATCHID or DOCUMENTNO, the database rejects the insert to preserve data integrity.

Questions

What typically triggers the "Violation of PRIMARY or UNIQUE KEY constraint 'INTEG_199'"?

When a reversal tries to insert a batch with an existing BATCHID or a duplicate DOCUMENTNO; the database blocks the duplicate to preserve integrity.

Do I need to restore a backup if I get this error?

Not immediately. First attempt the Fix Unique ID workflow, clear/reset temporary entries, or create a manual reversing journal. Always back up before running SQL or reset actions.

Can I safely retry the automated reverse after fixing IDs?

Yes — after resolving duplicate IDs and ensuring no partial reversals remain, retry the reverse. If it still fails, use manual reversal or contact support.