Re: Insert - integrity constraint violation

From: <sergey_s_at_my-deja.com>
Date: Wed, 23 Feb 2000 03:14:25 GMT
Message-ID: <88vjae$16u$1_at_nnrp1.deja.com>


Well, you have to have corresponding data in the parent table (B) before you can insert into the child table (A). That's the basic thing about constraints. Other than that, the syntax that you suppplied here for the constraints looks strange:

ALTER TABLE A
> ADD (CONSTRAINT
> A_fk_B
> FOREIGN KEY (column4)
> REFERENCES B);
It doesn't specify which column in table B to reference. But I guess it didn't give you an error... Here's how I would write the foreign key constraint:

ALTER TABLE A
  ADD CONSTRAINT A_fk_B
    FOREIGN KEY (column4) REFERENCES B.columnB;

Sergey

In article <88v49m$mpk$1_at_nnrp1.deja.com>,   ZC <zuin_chn_at_my-deja.com> 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);
>
> --
> Someone pass a cork to plug the hole in my head
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

Sent via Deja.com http://www.deja.com/
Before you buy. Received on Wed Feb 23 2000 - 04:14:25 CET

Original text of this message