Re: Insert - integrity constraint violation

From: SKurosky <skurosky_at_aol.com>
Date: 23 Feb 2000 02:23:43 GMT
Message-ID: <20000222212343.17859.00001148_at_ng-cn1.aol.com>


>zuin wrote:

> Need help,
>
>I have two tables. When I do an insert into table A, I get a message
>stating: integrity constraint (DATBASE1.A_FK_B) violated - parent key
>not found. Anyone know what I'm doing wrong that prevents me from
>entering the data into the table? The referenceor, referencee column
>are suposed to have the same type of data.
>
>I was thinking of some type of cascade insert, but I'm not sure oracle
>supports a cascade insert.
>
>Thanks for your input
>ZC
>
>A
>-----
>column1 NUMBER NOT NULL,
>column2 VARCHAR2(20) NOT NULL,
>column3 VARCHAR2(20) NULL,
>column4 VARCHAR2(20) NULL
>
>
>B
>-----
>columnA NUMBER NOT NULL,
>columnB VARCHAR2(20) NOT NULL,
>
>
>ALTER TABLE A
> ADD (CONSTRAINT A_pk
> PRIMARY KEY (column1));
>ALTER TABLE B
> ADD (CONSTRAINT B_pk
> PRIMARY KEY (columnA));
>
>ALTER TABLE A
> ADD (CONSTRAINT
>A_fk_B
> FOREIGN KEY (column4)
> REFERENCES B);
>
>
>--First: Yes, the columns have to be of the same type.

   Second: Your foreign key constraint is incorrect. Both in syntax and in the fact you are naming "column4" as the foreign key. If your Master table is A and your detail table is B then:

    alter table B
    add constraint a_fk_b foreign key (columnA)    references A (column1)

If your Master is B and Detail is A then:

    alter table A
    add constraint a_fk_b foreign key (column1)

    references B (columnA)  

HtH
Sandy

>Someone pass a cork to plug the hole in my head
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.
>
>
>
>
>
>
Received on Wed Feb 23 2000 - 03:23:43 CET

Original text of this message