Path: dp-news.maxwell.syr.edu!spool.maxwell.syr.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!postnews.google.com!h48g2000cwc.googlegroups.com!not-for-mail
From: "sybrandb" <sybrandb@gmail.com>
Newsgroups: comp.databases.oracle.server
Subject: Re: Integrity constraint violated
Date: 8 Aug 2006 04:19:36 -0700
Organization: http://groups.google.com
Lines: 39
Message-ID: <1155035976.755739.76650@h48g2000cwc.googlegroups.com>
References: <1155031051.370417.300980@i42g2000cwa.googlegroups.com>
NNTP-Posting-Host: 192.33.238.6
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-2"
X-Trace: posting.google.com 1155035981 10793 127.0.0.1 (8 Aug 2006 11:19:41 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 8 Aug 2006 11:19:41 +0000 (UTC)
In-Reply-To: <1155031051.370417.300980@i42g2000cwa.googlegroups.com>
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1),gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 PXYBEBR003
Complaints-To: groups-abuse@google.com
Injection-Info: h48g2000cwc.googlegroups.com; posting-host=192.33.238.6;
   posting-account=d8kqXg0AAADvDUR8IdYEU7pAZnZ1O2PC
Xref: dp-news.maxwell.syr.edu comp.databases.oracle.server:272352


mamin@o2.pl wrote:
> Hi,
> I have a database on Oracle 9.2. in schema TEST there're tables:
> zamowienia_pozycje and stawki_vat.
> While executing insert command::
>
> INSERT INTO ZAMOWIENIA_POZYCJE
> (ZAMOWIENIE_ID,OPERATOR_ID,POZYCJA_ASORTYMENTOWA_ID,POZYCJA_CENNIKA_ID,CENA,WARTOSC_WSPOLCZYNNIKOW,STAWKA_VAT_ID,
> STATUS_POZYCJI_ZAMOWIENIA_ID,LICZBA_SZTUK,ZLOZONA_NAZWA_POZYCJI)
> VALUES (4,1,6,1,2,1,1,1,1,'test')
>
> Oracle throws an exception:
> "ORA-02291: Integrity constraint violated (TEST.ZAM_POZ_STAWKA_VAT_FK)
> - parent key not found\n"
>
> There's a  ZAM_POZ_STAWKA_VAT_FK constraint script:
>
> --ZAM_POZ_STAWKA_VAT_FK
> --
> ALTER TABLE ZAMOWIENIA_POZYCJE ADD (
>   CONSTRAINT ZAM_POZ_STAWKA_VAT_FK FOREIGN KEY (STAWKA_VAT_ID)
>     REFERENCES FAKTURY_VAT (ID));
>
>
> Anybody knows, why this constrain is blocking my insert command?

Please read the error message *carefully* and try to understand it.
It tells you for the ZAMOWIENIA_POZYCJE record with stawka_vat_id 1,
there is no corresponding FAKTURY_VAT record, with ID 1.
Unless your constraints are deferred (so they are checked at commit),
the FAKTURY_VAT parent record needs to be present and committed prior
to inserting any ZAMOWIENIA_POZYCJE record with STAWKA_VAT_ID 1.


--
Sybrand Bakker
Senior Oracle DBA

