Subject Re: [firebird-support] DB restore and datapumping fails
Author Helen Borrie
At 01:11 AM 10/11/2007, you wrote:
>Hi,
>
>I have an Firebird 1.5 (classic on win) database which works OK with
>my app, but when tring to restore it from backup (backup will be done
>without errors) it fails with
>
>gbak -R -user ...
>gbak: ERROR: attempt to store duplicate value (visible to active
>transactions) in unique index "RDB$PRIMARY40"
>gbak: Exiting before completion due to errors
>
>In the RDB$INDICES table there is row where
> "RDB$INDEX_NAME" = RDB$PRIMARY40
> "RDB$RELATION_NAME" = TAB_GRAAFIK
> "RDB$INDEX_ID" = 1
> "RDB$UNIQUE_FLAG" = 1
> "RDB$SEGMENT_COUNT" = 1
> "RDB$INDEX_INACTIVE" = 0
> "RDB$INDEX_TYPE" = 0
>
>When trying to pump data to fresh database (using IBPump) it fails with
>
> ! Error 1:violation of PRIMARY or UNIQUE KEY constraint "INTEG_79"
>on table "TAB_GRAAFIK"
>!!! Fatal Error :violation of PRIMARY or UNIQUE KEY constraint
>"INTEG_79" on table "TAB_GRAAFIK"
>
>When looking into RDB$RELATION_CONSTRAINTS, then INTEG_79 seems to be
>PK constraint of TAB_Graafik indeed. The DDL of the table is
>
>CREATE DOMAIN DOM_PK AS INTEGER NOT NULL;
>CREATE DOMAIN DOM_FK AS INTEGER NOT NULL;
>
>CREATE TABLE TAB_Graafik (
> UID DOM_PK PRIMARY KEY,
> Vahetus DOM_FK CONSTRAINT FK_Vahetus_G REFERENCES TAB_Vahetus(UID)
>ON UPDATE CASCADE,
> Tooleping DOM_FK CONSTRAINT FK_TLeping_G REFERENCES
>TAB_Tooleping(UID) ON UPDATE CASCADE,
> Mustand DOM_WEAK_FK CONSTRAINT FK_TyypGrP_G REFERENCES
>TAB_TyypGrPaev(UID) ON UPDATE CASCADE ON DELETE SET NULL,
> Kuupaev DOM_KUUPAEV NOT NULL,
> Changed DOM_TIMESTAMP,
> CONSTRAINT CU_Graafik_KuupLepVah UNIQUE(Kuupaev,Tooleping,Vahetus)
>);
>
>Now AFAIK there is no dublicate values in PK field (query select uid
>from Tab_Graafik group by 1 having count(*)>1 returns empty set)...
>any ideas what is wrong and how to save the data?

NULL violates a primary key constraint too.

Try
select Kuupaev,Tooleping,Vahetus from Tab_Graafik
where uid is null

./heLen