Subject Re: Index error
Author Alexander V.Nevsky
--- In firebird-support@yahoogroups.com, "Michael Vilhelmsen"
<Michael.Vilhelmsen@M...> wrote:
> > Is there any message which foreihn key constraint is causing the
> error?
> > (ie sth. like INTEG_42)
>
> attempt to store duplicate value (visible to active transactions) in
> unique index "RDB$PRIMARY19

Michael, this is unique index which support PK constraint on one of
your tables. If you don't know what the table,

select rdb$relation_name from rdb$indices where
rdb$index_name='RDB$PRIMARY19'

This index is broken most probably due to power failure etc on your
customer's machine. As a result, table contains duplicate(s). Find
them

Select ID, Count(*)
From This_Table
Group By ID
Having Count(*) >1

(supposing you have one-segment PK on this table and column name is
ID) in database restored with inactive indices. Try

Select *
Group By ID
where ID Is Null

too (can exists in case if fragments of garbage records got status of
normal record because of corruption). After you find problem records,
make decision what make with them - delete or update. If you need rest
in place one record in group of duplicates and delete others, use
stored procedure like (supposing ID is integer)

Create Procedure Delete_Duplicates(ID Int)
As
Declare Variable TMP Int;
Begin
FOR SELECT SKIP 1 ID
FROM Damaged_Table
WHERE ID=:ID
INTO :TMP
AS CURSOR TMPCURSOR
DO
Delete From Damaged_Table
WHERE CURRENT OF TMPCURSOR;
End

if you need rest in place not any but particular record, remove
'SKIP 1' and avoid delete of this record on needed condition inside
loop body. You can use similar procedure to update duplicated IDs too.
Null-filled records (if exists) should be directly deleted.

> Internal gds software consistency check (partner index
> description not found(175))

It is secondary exception - FK can't be activaited if referenced PK
is'nt activated. After you'll repair and activate PKs this one should
disappear.

Best regards,
Alexander.